Inexplicable behavior in simple example of a set in a class

Saqib Ali saqib.ali.75 at gmail.com
Sat Jul 2 18:23:16 EDT 2011


> Instance variables are properly created in the __init__()
> initializer method, *not* directly in the class body.
>
> Your class would be correctly rewritten as:
>
> class MyClass2(object):
>     def __init__(self):
>         self.mySet = sets.Set(range(1,10))
>
>     def clearSet(self):
> # ...rest same as before...


Thanks Chris. That was certainly very helpful!!

So just out of curiosity, why does it work as I had expected when the
member contains an integer, but not when the member contains a set?



More information about the Python-list mailing list