[Tutor] FW: isinstance -> instance

Mike Hansen Mike.Hansen at atmel.com
Mon Feb 26 22:44:20 CET 2007


Oops...I replied instead of replied all. 

> -----Original Message-----
> From: Mike Hansen 
> Sent: Monday, February 26, 2007 2:43 PM
> To: 'Bernard Lebel'
> Subject: RE: [Tutor] isinstance -> instance
> 
>  
> 
> > -----Original Message-----
> > From: tutor-bounces at python.org 
> > [mailto:tutor-bounces at python.org] On Behalf Of Bernard Lebel
> > Sent: Monday, February 26, 2007 2:34 PM
> > To: Tutor
> > Subject: [Tutor] isinstance -> instance
> > 
> > Hello,
> > 
> > Following the guidelines here, at the bottom of the page:
> > http://www.python.org/dev/peps/pep-0008/
> > 
> > I'm using isinstance() to test the type of some data.
> > Now the thing is that, what is the name to use for a class instance?
> > 
> > For example, say I run this:
> > 
> > class A:
> >     def __init__( self ):
> >         self.a = 'a'
> > 
> > a = A()
> > 
> > print type( a )
> > 
> > Outputs:
> > <type 'instance'>
> > 
> > 
> > 
> > 
> > Now if I test against the instance type like I would for integer,
> > strings and the likes:
> > 
> > isinstance( a, instance )
> > 
> > Outputs:
> > NameError: name 'instance' is not defined
> > 
> > 
> > So I'm a bit at a loss here. I don't want to know if the instance is
> > an instance of a specific class, I just want to know if it's an
> > instance.
> > 
> > 
> > Thanks
> > Bernard
> 
> Shouldn't that be
> 
> isinstance(a, A)
> 
> ?
> 
> Mike 


More information about the Tutor mailing list