[Tutor] Why thus?

alan.gauld@bt.com alan.gauld@bt.com
Mon, 13 Mar 2000 17:47:27 -0000


> counter=0
> class Count:
>  def __init__(self):
>     print counter
> Count()

Uses the global counter

> counter=0
> class Count:
>  def __init__(self):
>   counter=counter+1

creates a new counter - except it can't coz you 
are trying to use the thus far uncreated counter 
to initialiuse itself!!!!

Try:

class Count:
   def __init__(self):
      	global counter # don't create local one
	counter = counter + 1
etc...

Alan g.