This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: vars() assignment fails silently when assignments made later
Type: behavior Stage:
Components: None Versions: Python 2.5
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: ocean-city, pest
Priority: normal Keywords:

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:


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


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) * (Python committer) Date: 2009-02-10 07:35
According to

>The returned dictionary should not be modified: the effects on the
>corresponding symbol table are undefined.

Same can be said for locals() as well.
Date User Action Args
2022-04-11 14:56:45adminsetgithub: 49447
2009-02-10 07:35:43ocean-citysetstatus: open -> closed
resolution: not a bug
messages: + msg81533
nosy: + ocean-city
2009-02-10 05:14:41pestcreate