Sharing method code between class instances

Gonçalo Rodrigues op73418 at mail.telepac.pt
Fri Jan 24 11:48:21 EST 2003


On Fri, 24 Jan 2003 10:19:53 -0600, "Larry Bates" <lbates at swamisoft.com>
wrote:

>I have a question about how to share code between classes.  I've searched
>and just can't find anything that is clear enough for me to understand.
>
>
>Problem: My program will create hundreds of instances of this field class
>and
>I'm worried about the code for each instance of the class being repeated
>over
>and over filling memory.  In this simple case it wouldn't be a problem, but
>the
>draw method will get rather large as I introduce MANY formatting parameters
>like fill characters, float characters, picture formats, etc. the draw
>method will
>become quite large/complex.
>

I think you are confused here. The code for the methods is kept in the
class object *not* in the instances. It is *shared* by all instances of
the class.

Hope this answers your question,
G. Rodrigues




More information about the Python-list mailing list