【问题标题】:Python 3.4 caused type function errorPython 3.4 导致类型函数错误
【发布时间】:2018-01-13 08:40:25
【问题描述】:

我是 python 的新手。我有 python 2.7 和 3.4。当我编译 python 3.4 时出现以下错误,但在 2.7 中没有

File "C:\pyprojects\focus\site\focus2\flow.py", line 24, in _wrapper
    cls._meta = type("Meta", (), BaseFlowTile.Meta.__dict__)
TypeError: type() argument 3 must be dict, not mappingproxy

如果我只使用 dict 而不是 __dict__ 那么我会收到以下错误

AttributeError: type object 'Meta' has no attribute 'dict'

非常感谢任何帮助。

【问题讨论】:

  • 非常抱歉,我读错了!
  • 我也改了标题和帖子,希望对你有帮助。

标签: python-2.7 python-3.x


【解决方案1】:

Python 3.3 引入了MappingProxyType,基本上允许了一些optimizations

您应该可以在两个 Python 版本中使用此副本:

cls._meta = type("Meta", (), BaseFlowTile.Meta.__dict__.copy())

【讨论】:

  • @PrithvirajMitra:确实需要一些时间来追踪 - 遇到像您这样有趣(不常见)的问题总是很高兴。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-06-02
  • 1970-01-01
  • 1970-01-01
  • 2014-07-01
相关资源
最近更新 更多