How to name my variable class dynamicly in python
<blockquote>
  <p><strong>Possible Duplicates:</strong><br>
  <a href="http://stackoverflow.com/questions/686715/python-why-cant-i-modify-the-current-scope-within-a-function-using-locals">Python: Why can&#39;t I modify the current scope within a function using locals()?</a><br>
  <a href="http://stackoverflow.com/questions/285061/how-do-you-programmatically-set-an-attribute-in-python">How do you programmatically set an attribute in Python?</a>  </p>
</blockquote>



<p>i know nammed dynamicly an varial in python with:</p>

<pre><code>var = "my_var"
locals()[var] = "coucou"
print my_var
&gt;&gt;coucou
</code></pre>

<p>But i don't know how to make it on a variable class.
When i try:</p>

<pre><code>class Controller(object):
    def __init__(self):
        var = 'ma_variable_dynamique'
        locals()[var] = 'toto'
        print ma_variable_dynamique
</code></pre>

<p>The exeception "NameError: global name 'ma_variable_dynamique' is not defined" is raised.</p>

<p>Example in php:</p>

<pre><code>class Users extends Controller{
    public $models = array(‘User’);

    function login(){
        $this-&gt;User-&gt;validate();
    }

    //Call in contructor
    function loadModel(){
        foreach($this-&gt;models as $m){
            $_class = $m.’Model’;s
            $this-&gt;{$m} = new $_class();
        }
    }
}
</code></pre>

<p>Thx</p>
