Dynamic assignment

Ingo Blank iblank at nospam.com
Fri Oct 26 04:59:14 CEST 2001


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
SyntaxError: invalid syntax

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



More information about the Python-list mailing list