473,394 Members | 1,889 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

where does __class__ come from?

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!

Aug 23 '05 #1
2 1593
> 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
Aug 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Mars | last post by:
I have looked long and hard at Mr. Martelli's Borg recipe: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66531 It is a very useful substitute for a Singleton, but I can't figure out...
6
by: gregory lielens | last post by:
Hello, I am currently writing python bindings to an existing C++ library, and I just encountered a problem that I hope has been solved by more experienced python programmers: A C++ class...
11
by: Rob Conner | last post by:
I'm still working on my DateTime class from last week... Why does __init__ not get called? The docs at http://www.python.org/dev/doc/devel/ref/customization.html read "If __new__() returns an...
5
by: Barry Kelly | last post by:
I'm running this version of Python: Python 2.4.3 (#1, May 18 2006, 07:40:45) on cygwin I read in the documentation that these two expressions are interchangeable: ...
4
by: alf | last post by:
Hi, is there a more elegant way to get o.__class__.__name__. For instance I would imagine name(o). -- alf
0
by: Gerard Brunick | last post by:
Consider: ### Function closure example def outer(s): .... def inner(): .... print s .... return inner .... 5
1
by: gregory.lielens | last post by:
Hello, We are currently writing python bindings to an existing C++ library, and we encountered a problem that some of you may have solved (or that has found unsolvable :( ): A C++ class...
18
by: Gabriel Rossetti | last post by:
Hello everyone, I had read somewhere that it is preferred to use self.__class__.attribute over ClassName.attribute to access class (aka static) attributes. I had done this and it seamed to work,...
1
by: The Pythonista | last post by:
I've been wondering for a while about whether assigning to __class__ is bad form or not. Specifically, I mean doing so when some other method of implementing the functionality you're after is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.