Python design philosophy

Paul Prescod paul at prescod.net
Wed Jun 28 18:05:27 EDT 2000


Eric Lee Green wrote:
> 
> ...
> This is one reason why inheritance is so efficient in Python, BTW. 

No, it isn't so efficient!

> All
> inheritence does is add into the hash table for the overall class object those
> entries that were in the base class object. 

Python actually delegates from one class object to another.

> 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 true. Python delegates.

>>> class a:
...     def foo(self): print foo
...
>>> dir( a )
['__doc__', '__module__', 'foo']
>>> class b(a):
...     def bar(self): print "bar"
...
>>> dir( b )
['__doc__', '__module__', 'bar']
>>> b.foo=b.foo
>>> dir( b )
['__doc__', '__module__', 'bar', 'foo']

You can hook up the more efficient inheritance at a cost of dynamicity
and memory, if you want.

-- 
 Paul Prescod - Not encumbered by corporate consensus
The calculus and the rich body of mathematical analysis to which it 
gave rise made modern science possible, but it was the algorithm that 
made the modern world possible.
	- The Advent of the Algorithm (pending), by David Berlinski




More information about the Python-list mailing list