Python Classes

Chris Angelico rosuav at gmail.com
Tue Aug 5 12:08:06 EDT 2014


On Wed, Aug 6, 2014 at 1:37 AM, Neil D. Cerutti <neilc at norwich.edu> wrote:
> In simple cases like that, functions could do very well by including a
> little bundle of data (probably a dict) as one of the parameters for each
> related function.

And this is exactly how object orientation is done in C. You just have
a structure that holds the object's state, and the (usually) first
parameter to each function is a pointer to that structure. Actually,
I've done that in high level languages too, specifically to decouple
the code from the state (and thus allow me to load new code from the
disk while maintaining state via what's already in memory - doing this
with classes and objects means importing that state explicitly). The
two notations are exactly the same. Compare:

list.append(l, 'spam')
l.append('spam')

One uses namespacing, the other uses object methods. Same thing!

ChrisA



More information about the Python-list mailing list