Changing the default for data to None and creating a new dict inside your function might handle this.  But I don't know what it is you want.  It never even occurred to me that this behavior might be desired in the first place.  <div>
<br></div><div><div>class Param(object):</div><div>   def __init__(self,data=None,condition=False):</div><div>       if data is None:</div><div>          data = {}</div><div>       if condition:</div><div>          data['class'] = 'Advanced'</div>
<div>       print data</div><div><br></div><div>Param(condition=True)</div><div>Param(condition=False)</div><div><br></div><div>I always thought you didn't want to have empty sequences as default values.</div><br><div class="gmail_quote">
On Tue, Jun 3, 2008 at 5:11 PM,  <<a href="mailto:pythonreptile@gmail.com">pythonreptile@gmail.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hello all,<br>
<br>
I have come across this issue in Python and I cannot quite understand<br>
what is going on.<br>
<br>
class Param():<br>
    def __init__(self, data={}, condition=False):<br>
        if condition:<br>
            data['class']="Advanced"<br>
        print data<br>
<br>
In the previous example, I expect the variable data to be re-<br>
initialized every time I construct an object type Param. However, when<br>
I do the following:<br>
<br>
Param(condition=True)<br>
Param(condition=False)<br>
<br>
The second call still prints {'class': 'Advanced'}<br>
<br>
Shouldn't data be initialized to {} since it is the default in<br>
__init__? Why would the state of data be preserved between two<br>
independent instantiations?<br>
<br>
Any help would be greatly appreciated.<br>
<br>
M.<br>
<font color="#888888">--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</font></blockquote></div><br><br clear="all"><br>-- <br>| _ | * | _ |<br>| _ | _ | * |<br>| * | * | * |
</div>