Python design philosophy
Gordon McMillan
gmcm at hypernet.com
Wed Jun 28 18:28:45 EDT 2000
Eric Lee Green wrote:
>Steve Juranich wrote:
>> I am *brand* new to python (as of Sunday), and I just got to the
>> section in the tutorial about classes. I was wondering why there
>> really isn't such an idea as a "private" member of classes?
>
>Mostly because Python doesn't "really" have classes. What Python
>"really" has are hash tables whose entries are objects (either methods
>or other data objects), and some syntactic sugar [...]
By this logic, all C++ has is pointers and some syntactic sugar.
>This is one reason why inheritance is so efficient in Python, BTW. All
>inheritence does is add into the hash table for the overall class object
>those entries that were in the base class object. Then when you create a
>new instance, you actually are just creating a copy of the overall class
>object, without having to refer back to the base object(s).
Not positive I understand what you're saying, but reality appears to
contradict it:
>>> class A:
... arg = 1
...
>>> class B(A):
... barg = 2
...
>>> class C(B):
... pass
...
>>> c = C()
>>> c.arg
1
>>> c.barg
2
>>> c.__class__.__bases__[0].__dict__
{'barg': 2, '__doc__': None, '__module__': '__main__'}
>>> c.__class__.__bases__[0].__bases__[0].__dict__
{'arg': 1, '__module__': '__main__', '__doc__': None}
>>>
- Gordon
More information about the Python-list
mailing list