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
クラスが見つからないのはなぜですか?
使用する前にクラスを定義します。
class Something:
def out(self):
print("it works")
s = Something()
s.out()
self
すべてのインスタンスメソッドに最初の引数として渡す必要があります。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加