Is types.InstanceType no longer valid with Python 2.2

Georg Lohrer GeorgLohrer at gmx.de
Fri Jan 4 11:29:03 EST 2002


Skip,

On Thu, 3 Jan 2002 10:17:13 -0600, Skip Montanaro <skip at pobox.com>
wrote:

[snipped]

>Try pasting a simple interactive session or script (with output) that
>demonstrates that this fails for you.

Python 2.2 (#28, Dec 21 2001, 12:21:22) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
IDLE 0.8 -- press F1 for help
>>> import types
>>> class foo:
	pass

>>> f = foo()
>>> type(f)
<type 'instance'>
>>> type(f) == types.InstanceType
1
>>> class foo2(object):
	pass

>>> f2 = foo2()
>>> type(f2)
<class '__main__.foo2'>
>>> type(f2) == types.InstanceType
0
>>> 

You see the problem?! With old-type classes the comparision succeeds,
with new-type classes it fails.
The type of the instance will show the whole class-structure, but
that's not of any interest (as mentioned in posting to Emile).
Okay, one way would be to compare the type of the object with all
other types in 'types' (except InstanceType). If all fail, the object
must be an instance of a class. Not very satisfying, is it.

Ciao, Georg



More information about the Python-list mailing list