title: Returning a Python object instance of an inner class of a function
body: <p>I wrote a function in Python that is supposed to work similar to a factory in Java, as it instances the correct class for the given parameters and returns this instance. </p>
  
  <p>A minimal example with only one class inside the function would be this:</p>
  
  <pre><code>def create_object(param):
  
      class SpecialClass(ParentClass):
          def func(self, param):
              doSomething()
  
      class_instance = SpecialClass(param)
      return class_instance
  </code></pre>
  
  <p>I can flawlessly use this object when I call this function from outside. Coming from a Java background, I assume this has something to do with the dynamic typing in Python but I'm still not sure why this actually works. Isn't the scope where that class is known just within the function itself? </p>