Dynamic variable creation from string

Jussi Piitulainen jpiitula at ling.helsinki.fi
Thu Dec 8 03:54:48 EST 2011


Terry Reedy writes:

> On 12/7/2011 7:03 PM, Steven D'Aprano wrote:
> > On Wed, 07 Dec 2011 09:09:16 -0800, Massi wrote:
> >
> >> Is there a way to create three variables dynamically inside Sum
> >> in order to re write the function like this?
> 
> I should have mentioned in my earlier response that 'variable' is a
> bit vague and misleading. Python has names bound to objects.

The language reference at python.org uses both terms - name and
variable - freely. Here is one instance.

<http://docs.python.org/py3k/reference/executionmodel.html#naming-and-binding>

# If a name is bound in a block, it is a local variable of that block,
# unless declared as nonlocal. If a name is bound at the module level,
# it is a global variable. (The variables of the module code block are
# local and global.) If a variable is used in a code block but not
# defined there, it is a free variable.

Perhaps you could consider accepting this. Or trying to change it. Or
starting to tell newcomers that the official documentation of the
language is, say, vague and misleading. (It seems good to me.)



More information about the Python-list mailing list