Python - Inner Class Not Found
<p>(Sorry I'm new to Python)</p>

<p>I'm running a python django script as follows:</p>

<p><code>python3 manage.py test</code></p>

<hr>

<pre><code>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
</code></pre>

<p>But I get the error that it can't be found?</p>

<pre><code>    gs = GoalScorerX(id, goal_type)
NameError: name 'GoalScorerX' is not defined
</code></pre>

<p>Inner classes are very rarely useful in Python. Certainly here there is nothing to be gained by making GoalScorerX an inner class. Move it outside; also note that there is no restriction in Python in the number of classes in a file, so it's fine to have them both as top-level classes.</p>

<p>(Note, you <em>could</em> fix this by referring to the inner class as Command.GoalScorerX - but don't do that.)</p>

python django