Constructor re-initialization issue

pythonreptile at pythonreptile at
Wed Jun 4 00:11:25 CEST 2008

Hello all,

I have come across this issue in Python and I cannot quite understand
what is going on.

class Param():
    def __init__(self, data={}, condition=False):
        if condition:
        print data

In the previous example, I expect the variable data to be re-
initialized every time I construct an object type Param. However, when
I do the following:


The second call still prints {'class': 'Advanced'}

Shouldn't data be initialized to {} since it is the default in
__init__? Why would the state of data be preserved between two
independent instantiations?

Any help would be greatly appreciated.


More information about the Python-list mailing list