Issue 5197: vars() assignment fails silently when assignments made later
Created on 2009-02-10 05:14 by pest, last changed 2022-04-11 14:56 by admin. This issue is now closed.
| Messages (2) | |||
|---|---|---|---|
| msg81530 - (view) | Author: (pest) | Date: 2009-02-10 05:14 | |
Assignments to vars() behave incorrectly if those variables are use
later on in a function.
For example, try this:
======
#!/usr/bin/python
def zz():
for i in [1,2,3]:
for j in [4,5,6]:
vars()['fw_%s_%s' % (j,i)] = 'test %s %s' % (j, i)
print vars()['fw_%s_%s' % (j,i)]
fw_4_2 = 'zz'
print fw_4_2
zz()
======
The assignments work fine up till 4_2. At 4_2, the assignment apparently
fails silently, and the print raises a keyError exception.
|
|||
| msg81533 - (view) | Author: Hirokazu Yamamoto (ocean-city) * ![]() |
Date: 2009-02-10 07:35 | |
According to http://docs.python.org/library/functions.html#vars >The returned dictionary should not be modified: the effects on the >corresponding symbol table are undefined. Same can be said for locals() as well. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:56:45 | admin | set | github: 49447 |
| 2009-02-10 07:35:43 | ocean-city | set | status: open -> closed resolution: not a bug messages: + msg81533 nosy: + ocean-city |
| 2009-02-10 05:14:41 | pest | create | |
