exec "global" problem

Michaell Taylor nytaylor at bestweb.net
Thu Jun 28 01:05:57 CEST 2001


I have seen lots of discussion of the problem of executing the following code:

global sub
sub=['sub1', 'sub2', ...'sub600']
def make():
	for X in range(1,600):
		exec "global sub%s" % (X)
		exec "sub%s={}" % (X)
		other stuff

The problem is the 

exec "global sub%s" % (X)

line which doesn't execute because of the timing of the execution of the exec 
and the global statements - which I don't entirely understand.  These 600 
dictionaries are subsequently passed to a variety of functions.

My real question is how can I get around this without specifying each of the 
600 variables which need global declarations.

Any ideas?

I really need a good wildcard as in : global sub*

=========================================
Debra Taylor




More information about the Python-list mailing list