Bruno Desthuilliers wrote: > a wrote: >> def fn(): >> for i in range(l) > > l is not defined - you should have an error here. > >> global count >> count[i]= .... >> >> how do i declare count to be global if it is an array > > Just like it was an integer
No. If he's only mutating "count", he doesn't need a global declaration. >> subsequently i should access or define count as an array > > You need to define count before. > >> error: >> global name 'count' is not defined > > He... > > *but* > You probably should not do that anyway. Globals are *evil*. Do you realize that every variable you set in a module's namespace is a global when used by a function? Globals are *not* evil. > And functions modifying globals is the worst possible thing. > There are very few chances you *need* a global here. Look at the use case first. For small scripts, sometimes re-assigning global names or mutating objects refered to by global names is essential. For large-scale packages, though, I agree with you that mutating globals is bad. Georg -- http://mail.python.org/mailman/listinfo/python-list