Inheriting frozenset gives bug if i overwrite __repr__ method

srinivasan srinivas sri_annauni at yahoo.co.in
Wed Nov 19 07:39:38 EST 2008


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.

Thanks,
Srini



      Add more friends to your messenger and enjoy! Go to http://messenger.yahoo.com/invite/



More information about the Python-list mailing list