Derivative of string as a name of list or dictionary (or class?)
John Hunter
jdhunter at nitace.bsd.uchicago.edu
Fri Jul 26 12:54:35 EDT 2002
>>>>> "Alex" == Alex Martelli <aleax at aleax.it> writes:
Alex> Sure, but the frown is first of all against the very task
Alex> that the OP wants to perform: setting arbitrary names in the
Alex> global space.
Alex> What if one of the name is 'print'? Boom. Python has a
Alex> couple of dozen keywords -- what ensures against attempts to
Alex> redefine one?
While I agree whole heartedly that it's best to do this on attributes
of a class, what do you think of the following approach to
manipulating globals, which I discovered doing a little more reading
on this issue in the c.l.python archives.
name = 'seq'
val = ['John', 'Hunter', 'was', 'here']
globals()[name] = val
print seq
globals()['print'] = 'Clobber?'
print seq #no clobber
John Hunter
More information about the Python-list
mailing list