[Tutor] help on scope

Charlie Clark Charlie Clark <charlie@begeistert.org>
Sun, 22 Jul 2001 19:33:50 +0200


Consider this:

count = 0

def func(something):
    print count
    count += 1

This will print 0 but generate an error about the assignment. I know this is 
a scope problem but my brain is having trouble with accepting the fact that 
although I can access a variable I can't reference it. Do I have to use 
global to get around this? How does global actually work?

def func(something):
    global count
    print count
    count += 1

Thanx for any help.

Charlie
-- 
Charlie Clark
Helmholtzstr. 20
Düsseldorf
D- 40215
Tel: +49-211-938-5360
GSM: +49-178-463-6199
http://www.begeistert.org