Python design philosophy

Eric Lee Green eric at estinc.com
Wed Jun 28 15:28:37 EDT 2000


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 for instantiating, calling methods within,
and zapping these guys. Thus a class instance 'foo' with methods 'bar' and
'grr' and data values 'ugh' and 'umm' would actually be a hash table with four
items in it, { 'bar': <some method> , 'grr': <some method>, 'ugh': 0, 'foo':
555 } and then 'foo.bar(x)' is syntactic sugar for foo['bar'](foo,x) . Though
the interpreter of course will not accept the latter syntax (it enforces the
class syntax). 

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). 

-- 
Eric Lee Green                         eric at estinc.com
Software Engineer                      Visit our Web page:
Enhanced Software Technologies, Inc.   http://www.estinc.com/
(602) 470-1115 voice                   (602) 470-1116 fax



More information about the Python-list mailing list