title: Can I create a funtion in python that will create an instance of a class?
body: <p>So I'm having this problem: I have created a class and would like to also create a function that allows to create an instance in order to make it reusable. The code I have doesn't work and I have trouble understanding why. 
  See for yourselves: </p>
  
  <pre><code>class Avatar(object):
  
      def __init__(self, name, money):
          self.name = name
          self.money = money
  
  
  def create_avatar(name, money):
      avatar = Avatar(name, money)
  </code></pre>
  
  <p>And later be able to call:</p>
  
  <pre><code>create_avatar("test", 50)
  </code></pre>
  
  <p>Is it at all possible to do it this way? It seems pretty straight forward and logical but doesn't work...
  If I then try to call:</p>
  
  <pre><code>avatar.name
  </code></pre>
  
  <p>I get:</p>
  
  <pre><code>Traceback (most recent call last):
    File "&lt;pyshell#2&gt;", line 1, in &lt;module&gt;
      avatar.name
  NameError: name 'avatar' is not defined
  </code></pre>
  
  <p>And is there a way to automatically change the variable 'avatar' to the name entered when calling. Or any other more efficient to avoid repeating the same variable...</p>
  
  <p>Thanks for your help!</p>