dynamic type changing

andychambers2002 at yahoo.co.uk andychambers2002 at yahoo.co.uk
Sun May 28 10:07:16 CEST 2006


>> I'm working on a "TempFile" class that stores the data in memory until
>> it gets larger than a specified threshold (as per PEP 42).  Whilst
>> trying to implement it, I've come across some strange behaviour.  Can
>> anyone explain this?

>> The test case at the bottom starts a TempFile at size 50 and prints its
>> type.  It then increases the size to the threshold at which point
>> "self" is changed to being a TemporaryFile.

> Changed how ?-)

Just by being assigned with a TemporaryFile object.  I thought that if
you do

instance = TempFile()

that "instance" and "self" defined in the Class were the same thing so
that if you changed the class of self, the class of instance would also
change.

Thanks very much for your example.  It has solved my problem and helped
me understand a new pattern at the same time.




More information about the Python-list mailing list