Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #19757
| Date | 2012-02-01 15:59 -0800 |
|---|---|
| From | Ethan Furman <ethan@stoneleaf.us> |
| Subject | Re: Question about name scope |
| References | (5 earlier) <CALwzid=qdawuq7qd2Qyj9xR1jUo-KLhYMKDwLxDHX06ZJ8aDOw@mail.gmail.com> <4F29C255.1050009@stoneleaf.us> <CALwzidkEL14pG3m3Pb=fQQin-YUTTwJ1PF4bCJaV3OYfwB2zTw@mail.gmail.com> <4F29CDC7.2000104@stoneleaf.us> <CALwzidkALwUzNvJLrEKtXBxeShtRT95xdKkqruoQiup9+O5q9A@mail.gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.5336.1328140417.27778.python-list@python.org> (permalink) |
Ian Kelly wrote:
> On Wed, Feb 1, 2012 at 4:41 PM, Ethan Furman <ethan@stoneleaf.us> wrote:
>> I'm not sure what you mean by temporary:
>>
>> --> def f(x, y):
>>
>> ... frob = None
>> ... loc = locals()
>> ... loc[x] = y
>> ... print(loc)
>> ... print(locals())
>> ... print(loc)
>> ... print(locals())
>> ...
>> -->
>> --> f('frob', 19)
>> {'y': 19, 'x': 'frob', 'frob': 19}
>> {'y': 19, 'x': 'frob', 'frob': None, 'loc': {...}}
>> {'y': 19, 'x': 'frob', 'frob': None, 'loc': {...}}
>> {'y': 19, 'x': 'frob', 'frob': None, 'loc': {...}}
>>
>> Seems to be stuck that way.
>
> The first print is the one that is incorrect. It suggests that the
> local 'frob' has been changed to 19 as it has in the dict, but the
> actual value of the local is still None. The second print on
> accurately reflect that.
Ah. Thanks for the explanations.
~Ethan~
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Question about name scope Olive <diolu@bigfoot.com> - 2012-02-01 18:11 +0100
Re: Question about name scope Rick Johnson <rantingrickjohnson@gmail.com> - 2012-02-01 09:21 -0800
Re: Question about name scope Ethan Furman <ethan@stoneleaf.us> - 2012-02-01 09:43 -0800
Re: Question about name scope Dave Angel <d@davea.name> - 2012-02-01 12:36 -0500
Re: Question about name scope Mel Wilson <mwilson@the-wire.com> - 2012-02-01 13:47 -0500
Re: Question about name scope Ian Kelly <ian.g.kelly@gmail.com> - 2012-02-01 14:49 -0700
Re: Question about name scope Ian Kelly <ian.g.kelly@gmail.com> - 2012-02-01 15:38 -0700
Re: Question about name scope Ethan Furman <ethan@stoneleaf.us> - 2012-02-01 14:24 -0800
Re: Question about name scope Ian Kelly <ian.g.kelly@gmail.com> - 2012-02-01 16:00 -0700
Re: Question about name scope Ethan Furman <ethan@stoneleaf.us> - 2012-02-01 15:08 -0800
Re: Question about name scope Ian Kelly <ian.g.kelly@gmail.com> - 2012-02-01 16:47 -0700
Re: Question about name scope Ethan Furman <ethan@stoneleaf.us> - 2012-02-01 14:53 -0800
Re: Question about name scope Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-02-02 00:34 +0000
Re: Question about name scope Ethan Furman <ethan@stoneleaf.us> - 2012-02-01 15:59 -0800
Re: Question about name scope Ethan Furman <ethan@stoneleaf.us> - 2012-02-01 15:41 -0800
Re: Question about name scope Ethan Furman <ethan@stoneleaf.us> - 2012-02-01 15:51 -0800
Re: Question about name scope Chris Rebert <clp2@rebertia.com> - 2012-02-01 09:38 -0800
Re: Question about name scope Christian Heimes <lists@cheimes.de> - 2012-02-01 18:50 +0100
csiph-web