By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,942 Members | 1,788 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,942 IT Pros & Developers. It's quick & easy.

Two instances share an attribute

P: n/a
I really don't understand, what's happening with the following code.
Am I doing something wrong?


class EnumeratedContent:

def __init__(self, values = []):
self.values_ = values

def values(self):
return self.values_

def addValue(self, value):

x = EnumeratedContent()
print x.values()
x = EnumeratedContent()
print x.values()

This code prints:

['ff', 'gg']

Why the heck self.__values keeps old list? Can anyone explain it to me?

I am using:

Python 2.5.2 (r252:60911, Sep 14 2008, 23:49:00)
[GCC 4.1.2 (Gentoo 4.1.2 p1.0.2)] on linux2
Filip GruszczyƄski
Nov 15 '08 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.