Re: Determining if an object is a class?

2006-07-13 Thread placid
[EMAIL PROTECTED] wrote: I need to find out if an object is a class. Using new style classes this is very easy: class Test(object): pass obj = Test or obj = Test() if type(obj) == type: # this is a class object.. else: # this not a class object But this fails for old

Re: Determining if an object is a class?

2006-07-13 Thread Michele Simionato
[EMAIL PROTECTED] wrote: I need to find out if an object is a class. Which is quite simply awful...does anyone know of a better way to do this? inspect.isclass M.S. -- http://mail.python.org/mailman/listinfo/python-list

Re: Determining if an object is a class?

2006-07-13 Thread Nick Vatamaniuc
Clay, Search Google for it. Here is one good explanation with code examples by Michael Fotsch: http://www.geocities.com/foetsch/python/new_style_classes.htm Nick V. placid wrote: [EMAIL PROTECTED] wrote: I need to find out if an object is a class. Using new style classes this is very easy:

Re: Determining if an object is a class?

2006-07-13 Thread Michael Spencer
Michele Simionato wrote: [EMAIL PROTECTED] wrote: I need to find out if an object is a class. Which is quite simply awful...does anyone know of a better way to do this? inspect.isclass M.S. ...which made me wonder what this canonical test is. The answer: def isclass(object):

Re: Determining if an object is a class?

2006-07-13 Thread Fredrik Lundh
placid wrote: Why is there old and new classes? What are the differences? the what's new document for the release where they were introduced (2.2) contains a nice overview, written from a before and after perspective: http://www.python.org/doc/2.2.3/whatsnew/sect-rellinks.html

Re: Determining if an object is a class?

2006-07-13 Thread Clay Culver
Dino Viehland wrote: The first check is also off - it should if issubclass(type(Test), type): otherwise you miss the metaclass case: class foo(type): pass class Test(object): __metaclass__ = foo obj = Test if type(obj) == type: 'class obj' else: 'not a class' just on the

Determining if an object is a class?

2006-07-12 Thread Clay_Culver
I need to find out if an object is a class. Using new style classes this is very easy: class Test(object): pass obj = Test or obj = Test() if type(obj) == type: # this is a class object.. else: # this not a class object But this fails for old style classes. For example: class

Re: Determining if an object is a class?

2006-07-12 Thread infidel
import types class OldStyle: pass ... type(OldStyle) == types.ClassType True -- http://mail.python.org/mailman/listinfo/python-list

Re: Determining if an object is a class?

2006-07-12 Thread Clay Culver
Ahh much better. Thanks. -- http://mail.python.org/mailman/listinfo/python-list

RE: Determining if an object is a class?

2006-07-12 Thread Dino Viehland
The first check is also off - it should if issubclass(type(Test), type): otherwise you miss the metaclass case: class foo(type): pass class Test(object): __metaclass__ = foo obj = Test if type(obj) == type: 'class obj' else: 'not a class' just on the off-chance you run into a metaclass :)