【发布时间】:2018-08-20 02:10:02
【问题描述】:
>>> import attr
>>> @attr.s
... class SmartClass(object):
... a=attr.ib()
... b=attr.ib()
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'attr' has no attribute 's'
>>>
我不明白为什么它不起作用。我已经使用 pip 安装了这个模块,并且安装正确,但在实现部分仍然显示错误。
【问题讨论】:
-
你用的是哪个版本的Python?
-
你有没有将这段代码(或其他一些
attr-使用代码)放入当前工作目录中名为attr.py的脚本中? -
pip 9.0.1 来自 /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages (python 3.5)
-
在类定义之前不用@attrs 吗?这使它对我有用
-
如果您尝试测试示例代码,那么您错过了装饰器。
标签: python