我有一个 python 脚本,但收到以下错误:
Traceback (most recent call last):
File "C:\Users\Tim\Desktop\pop-erp\test.py", line 1, in <module>
s = Something()
NameError: name 'Something' is not defined
这是导致问题的代码:
s = Something()
s.out()
class Something:
def out():
print("it works")
这是在 Windows 7 x86-64 下使用 Python 3.3.0 运行的。
为什么找不到 Something
类?
原文由 user1899679 发布,翻译遵循 CC BY-SA 4.0 许可协议
在使用之前定义类:
您需要将
self
作为所有实例方法的第一个参数传递。