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.

Author eric.smith
Recipients docs@python, eric.smith, ssc
Date 2010-10-07.12:31:13
SpamBayes Score 2.1558789e-08
Marked as misclassified No
Message-id <1286454676.64.0.0604361872436.issue10043@psf.upfronthosting.co.za>
In-reply-to
Content
It's a well documented behavior.

Surely you ran across this link while researching your problem? http://docs.python.org/reference/executionmodel.html#naming-and-binding
The paragraph beginning "The following constructs bind names ..." describes why setattr does not create a binding, although I'll grant that it doesn't mention setattr by name. The paragraph beginning "If a name binding operation occurs anywhere within a code block ..." explains why the assignment affects code that occurs before the binding.

If you'd like to improve the docs, please suggest a patch.

Also note that you're not creating a local variable with setattr, you're creating a module level (sometimes called global) variable. Perhaps that's part of the misunderstanding? You might want to look into the global (on nonlocal) statement, unless there's some particular reason the name you're creating needs to be dynamically computed.
History
Date User Action Args
2010-10-07 12:31:16eric.smithsetrecipients: + eric.smith, docs@python, ssc
2010-10-07 12:31:16eric.smithsetmessageid: <1286454676.64.0.0604361872436.issue10043@psf.upfronthosting.co.za>
2010-10-07 12:31:14eric.smithlinkissue10043 messages
2010-10-07 12:31:13eric.smithcreate