Okay..... right now I'm using types.InstanceType approach.

To elaborate on the context of my question, I have this module whose
only job is to test an object against a large array of types. The
thing is that I never know in advance what is going to be the data,
and it could be just about anything (string, int, float, bool, class
object, class instance, etc), and I never in advance against what type
it will be tested. Plus, in case the data is an instance of a class I
have coded, the module never knows what is the actual class object the
instance is obtained from.

Only the functions making call to this module "know" what they expect
from the module. There are countless of such functions, and each has
its own specificities.

So I'm aiming as a generic code as possible, where only the type of
the object is relevant, without any need for additional data.


Thanks
Bernard




On 2/26/07, Kent Johnson <[EMAIL PROTECTED]> wrote:
> Jerry Hill wrote:
> > I believe you can check for an instance of a new-style class
> > with:
> > isinstance(a, object)
>
> I'm not sure if that will ever fail. Given values from my previous post,
> I get:
> In [16]: isinstance(a, object)
> Out[16]: True
> In [17]: isinstance(A, object)
> Out[17]: True
> In [18]: isinstance(b, object)
> Out[18]: True
> In [19]: isinstance(types, object)
> Out[19]: True
> In [20]: def f(): pass
>     ....:
> In [21]: isinstance(f, object)
> Out[21]: True
>
> Kent
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to