New-style classes (was Re: Checking for EOF in stream)

GiBo gibo at gentlemail.com
Mon Feb 19 21:07:04 EST 2007


Gabriel Genellina wrote:
> En Mon, 19 Feb 2007 22:30:59 -0300, GiBo <gibo at gentlemail.com> escribió:
> 
>> Is there a reason why some classes distributed with Python 2.5 are not
>> new-style classes? For instance StringIO is apparently "old-style" class
>> i.e. not inherited from "object". Can I somehow turn an existing
>> old-style class to a new-style one? I tried for example:
>> 	class MyStreamIO(StreamIO, object):
>> 		pass
>> but got an error.
> 
> Try again (and look carefully the error text)

Ahhh, thanks! ;-)

Just for the record:

import StringIO
class MyStringIO(StringIO, object):
	pass

must of course be:

class MyStringIO(StringIO.StringIO, object):
	pass

One more question - is it likely that StringIO will be turned into
new-style class in the future? The reason I ask is whether I should try
to deal with detection of new-/old-style classes or take the
old-styleness for granted and set in stone instead.

GiBo



More information about the Python-list mailing list