Dynamic assignment

Ingo Blank iblank at nospam.com
Thu Oct 25 22:59:14 EDT 2001


Hi,

I want to dynamically create variables and assign values to them.

I tried the following:

>>> vn = "dynVar"
>>> vv = 1
>>> eval("%s=%d" % (vn,vv))
Traceback (most recent call last):
  File "<interactive input>", line 1, in ?
  File "<string>", line 1
    dynVar=1
          ^
SyntaxError: invalid syntax

Q1: Why is the "syntax error" issued ?
Q2: *HOW* do I achieve a dynamic assignment ?

TIA

--ibl






More information about the Python-list mailing list