Last message ( Scope & globals & binding )

Steven D. Majewski (sdm7g@aemsun.med.Virginia.EDU)
Fri, 6 Dec 91 14:31:14 EST

That was probably an incorrect statement to say that globals are
READONLY. The problems is not with globals but with assignment.
i.e. One reason this wasn't clear sooner was that I did not run
into this problem with globals that were LISTS because I did not
assign to them, but used the access method .append(). So therefore
global LISTS were updated correctly.
I used assignment for scalars.

Classes, BTW, do work:

class Global():
pass

G = Global()
G.k = 1000

def decK():
G.k = G.k - 1
return G.k

... etc...
Works as an assignable global variable.

Alternately, scalars could be one element lists, and assignment
done with replacement of the list element.
( Or put all (module wide) globals into a dictionary and replace
the values ? - I haven't tried that yet. )

Possibly my problems originated with a poor design in the first place -
( Stuffing things into globals was a quick hack to test an additional
feature. ) But I do think those issues DO need to be made clear(er)
in the user-guide. Reading the misc/CLASSES doc helped, but I don't
think the logic is explicitly spelled out in the user guide.

- Steve