On Nov 19, 12:39 pm, srinivasan srinivas <[EMAIL PROTECTED]> wrote: > 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'
I guess you need to implement the difference method in your subclass. It's a little odd that an operation on subclasses of frozenset returns an instance of the subclass, rather than simply a frozenset. Most other Python types don't work that way. Compare and contrast: Python 2.5.1 (r251:54863, Jan 17 2008, 19:35:17) [GCC 4.0.1 (Apple Inc. build 5465)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> class myint(int): pass ... >>> a = myint(3) >>> b = myint(5) >>> c = a+b >>> c 8 >>> type(c) <type 'int'> >>> class fs(frozenset): pass ... >>> a = fs([1, 2, 3]) >>> b = fs([3, 4, 5]) >>> c = a - b >>> c fs([1, 2]) >>> type(c) <class '__main__.fs'> >>> Mark -- http://mail.python.org/mailman/listinfo/python-list