0
が見つかりません(申し訳ありませんが、私は、Pythonに新たなんだ)パイソン - 内部クラス
次のように私はPythonのDjangoのスクリプトを実行している:
python3 manage.py test
class Command(NoArgsCommand):
help = 'Help Test'
def handle(self, **options):
gs = self.create_goalscorer(1,"Headed")
class GoalScorerX(object):
id = 0
goal_type = ""
#Constructor
def __init__(self, id, goal_type):
self.id= id
self.goal_type = goal_type
def create_goalscorer(self,id,goal_type):
gs = GoalScorerX(id, goal_type)
return gs
しかし、私をそれが見つからないというエラーが表示されますか?
gs = GoalScorerX(id, goal_type)
NameError: name 'GoalScorerX' is not defined
それは 'self'を使用しても大丈夫ですか? 'gs = self.GoalScorerX(id、goal_type)' – qmaruf
それはうまくいくかもしれませんが、意味的に間違っています。 GoalScorerはインスタンスの属性ではありません。私が言うように、Commandクラスからそれを取り除くべきです。 –