classes and functions

Bruno Desthuilliers bdesth.quelquechose at free.quelquepart.fr
Fri Mar 2 18:32:05 EST 2007


Silver Rock a écrit :
> Friends,
> 
> I don´t see why using classes.. functions does everything already. I
> read the Rossum tutotial and two other already.
> 
> Maybe this is because I am only writing small scripts, or some more
> serious misunderstandings of the language.

or both ?-)

If you only write small scripts, then you may not have a use for 
classes. OTOH, everything in Python (including functions) is an object - 
that is, an instance of a class. So as soon as you're coding in Python, 
you are at least using classes one way or another. The nice thing is 
that you can safely ignore this if doesn't make sens to you !-)

One of the benefit of classes is that they allow you to have many 
instances of the same object, each with it's own values - while if you 
only use functions + global variables (to share state between 
functions), you only have one set of values (one 'instance') at a time. 
This is probably no big deal in your case, but it becomes quite useful 
as soon as your scripts start to turn into a full blown application.

My 2 cents...



More information about the Python-list mailing list