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

Re: Inheriting frozenset gives bug if i overwrite __repr__ method

P: n/a
srinivasan srinivas wrote:
Hi,
I am getting an error while executing the following snippet. If i comment out method __repr__ , it works fine.

class fs(frozenset):
def __new__(cls, *data):
data = sorted(data)
self = frozenset.__new__(cls, data)
self.__data = data
return self

def __repr__(self):
return "%s(%r)" % (self.__class__.__name__, self.__data)

a1 = fs(1,2,3)
a2 = fs(3,4,5)
print a1.difference(a2)

Error:
return "%s(%r)" % (self.__class__.__name__, self.__data)
AttributeError: 'fs' object has no attribute '_fs__data'

Please help me in fixing this.
When posting problems like this, please include the Python version.
If you ran this with 2.6, please run the following:

x = frozenset('abc')
y = frozenset('bcd')
z = x.difference(y)
print(id(x) != id(z))

This should print (True), but if 2.6 has a bug for frozenset similar one
it has for bytearrays, it will print (False) and that would explain your
error.

tjr

Nov 19 '08 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.