Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > where does __class__ come from?

Reply
Thread Tools

where does __class__ come from?

 
 
patrick.m.lahey@aero.org
Guest
Posts: n/a
 
      08-23-2005
Newbie here...

Ok, the following code:

class Base:
_count = 0
def __init__(self):
self.__class__._count += 1
print dir(self)

x = Base()

the output is:

['__doc__', '__init__', '__module__', '_count']

Notice that __class__ is no where to be seen!

Where does __class__ come from, what does it mean and what else is
being hidden?

I am used to using dir(...) to figure out what I can play with.
Clearly that does not always work...

Thanks!

 
Reply With Quote
 
 
 
 
wittempj@hotmail.com
Guest
Posts: n/a
 
 
Reply With Quote
 
 
 
 
Diez B. Roggisch
Guest
Posts: n/a
 
      08-23-2005
> Where does __class__ come from, what does it mean and what else is
> being hidden?
>
> I am used to using dir(...) to figure out what I can play with.
> Clearly that does not always work...


Your question has benn answered - let me just add this from the dir()-docs:

Note: Because dir() is supplied primarily as a convenience for use at
an interactive prompt, it tries to supply an interesting set of names
more than it tries to supply a rigorously or consistently defined set
of names, and its detailed behavior may change across releases.

from

http://docs.python.org/lib/built-in-funcs.html

Regards,

Diez
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
More elegant to get a name: o.__class__.__name__ alf Python 4 12-09-2006 05:16 AM
__getattribute__ doesn't work on 'type' type for '__class__' Barry Kelly Python 5 06-20-2006 11:17 PM
Assigning to self.__class__ Paul McGuire Python 4 01-26-2006 08:38 PM
subclassing extension type and assignment to __class__ gregory lielens Python 6 12-02-2004 10:45 AM
tp_base, tp_basesize, and __slots__ instance __class__ reassignment Jp Calderone Python 1 07-06-2003 07:17 AM



Advertisments