By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,264 Members | 1,767 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,264 IT Pros & Developers. It's quick & easy.

type() for new style classes - buggy?

P: n/a
hello,

does the type() command work correctly for new style classes? i guess
it does not, unfortunately. for example, for a new style class'
instance it returns <class '__main__.ClassName'>, but for old style
class' instance it returns <type 'instance'>.
import types
class A(object): pass class B: pass type(A()) <class '__main__.A'> type(B()) <type 'instance'> type(A()) == types.InstanceType 0 type(B()) == types.InstanceType

1

how can one then determine what he's working with when he uses new
style classes (either instance or class)?

thank you,
--
fuf (fu*@mageo.cz)

Jul 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a


In the case of new style classes type actually doubles up as a class
constructor, so all classes including type itself are instances type.
class A(object): .... pass
.... a = A()
type(a) <class '__main__.A'> type(A) <type 'type'> isinstance(A, type) True isinstance(a, type) False isinstance(type, type) True


hope this helps
there is some documentation on new style classes you might want to read.
http://www.python.org/doc/newstyle.html
particularly the first essay by Guido.


Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.