Unexpected default arguments behaviour (Maybe bug?)
sukkopera at gmail.com
sukkopera at gmail.com
Sun Jul 13 12:02:19 EDT 2008
Hi, I have just encountered a Python behaviour I wouldn't expect. Take
the following code:
------------------------------------------------------------------------
class Parent:
a = 1
def m (self, param = a):
print "param = %d" % param
class Child (Parent):
a = 2
p = Parent ()
p.m ()
c = Child ()
c.m ()
------------------------------------------------------------------------
I would expect to receive the following output:
param = 1
param = 2
But actually I get:
param = 1
param = 1
Is this the correct behaviour, and then why, or is it a bug? For
reference, I am using Python 2.5.1 on UNIX.
Thanks in advance!
More information about the Python-list
mailing list