Bug?? reusing objects

Damian Menscher menscher+python at uiuc.edu
Sun May 26 00:28:40 EDT 2002


The following test program demonstrates what I believe is a bug:
-------------------------------------------------------------
#!/tmp/Python-2.2.1/python

class foobar:
   def __init__(self, string=[]):
      self.data = string
   def add(self, new=""):
      self.data.append(new)

a = foobar("foo")
print a.data

a = foobar("bar")
print a.data

a = foobar()
print a.data

a.add("foo")
a.add("bar")
print a.data

a = foobar()
print a.data   ### returns ['foo', 'bar'] for me
               ### I'd expect it to return []
-------------------------------------------------------------
If this is expected behavior, could someone please explain it?
Otherwise, I'll be happy to file a bug report.

Damian Menscher
-- 
-=#| Physics Grad Student & SysAdmin @ U Illinois Urbana-Champaign |#=-
-=#| 488 LLP, 1110 W. Green St, Urbana, IL 61801 Ofc:(217)333-0038 |#=-
-=#| 1429 DCL, Workstation Services Group, CITES Ofc:(217)244-3862 |#=-
-=#| <menscher at uiuc.edu> www.uiuc.edu/~menscher/ Fax:(217)333-9819 |#=-



More information about the Python-list mailing list