[Tutor] >> Bananas << A -bunch- of replying.

alan.gauld@bt.com alan.gauld@bt.com
Fri, 9 Mar 2001 20:11:42 -0000


> *** I am using a banana class, from my flora.py module.  ...
> The problem lies in the function to generate unique names.  It has to
> get the initial slate of names as it generates each instance 
> ...  So, what I've done is to create a dictionary that can hold a
> banana_count item.  

Take a look at class variables.

class Banana:
    count = 0
    def __init__(....

Now you can globally access Banana.count anywhere you 
can access Banana

Classes are just fancy dictionaries under the hood ;-)

On the subject of scope you might try my tutorial page 
on namespaces...

Alan G.
http://www.crosswinds.net/~agauld/