Is types.InstanceType no longer valid with Python 2.2

Georg Lohrer GeorgLohrer at gmx.de
Thu Jan 3 11:49:34 EST 2002


Emile,

On Thu, 3 Jan 2002 07:39:28 -0800, "Emile van Sebille"
<emile at fenx.com> wrote:

[snipped]
>
>assert isinstance(ff, foo)

thanks for coming back. It's a pity, but I really have to apologize
for myself not having spended more time to describe my problem in
shorter terms.

I'm only looking for a solution to decide wether a variable is an
instantiated object. The class's name is not of any interest.

In my special case I 'flatten' a deeply structured Python-object via
recursively calling a small helper script. Inside of that the type of
the current passed variable to flatten have to be decided. The
algorithm itself does not know anything about the type. It's only some
sort of meta-processing -- only dealing with the data, not changing or
interpreting them.
If the passed variable is an instance of a class, the __dict__ entries
will be examined by calling the algorithm again. Lists and
dictionaries have to be handled in a different manner.

Therefore I need recognizing an instantion of a class. If I could be
assured that only a class-instantiation could have a __dict__ then a
possible solution would be try..catch AttributeError to catch all
other items. But with Python 2.1 the InstanceType decision was more
elegant.

Ciao, Georg




More information about the Python-list mailing list