Can't do a multiline assignment!

Steve Holden steve at holdenweb.com
Thu Apr 17 19:45:00 CEST 2008


Marco Mariani wrote:
> s0suk3 at gmail.com wrote:
> 
>> Yes, it makes it more readable. And yes, it does make it (a lot) more
>> maintainable. Mainly because I don't have those four variables, I have
>> about thirty. And I think I won't need to one or two of them, but
>> maybe all of them at once.
> 
> have fun with locals(), then (but please feel dirty :-)
> 
> loc = locals()
> for var in [
>          'foo',     # INSERT
>          'bar',     # COMMENT
>          'baz'      # HERE
>          ]:
>      loc[var] = 42
> 
And bear in mind there is an explicit notification of the danger of this 
course of action in the CPython documentation, which refuses to 
guarantee that changes made to the object returns by locals() will ve 
reflected in the local namespace.

You have been warned.

regards
  Steve
-- 
Steve Holden        +1 571 484 6266   +1 800 494 3119
Holden Web LLC              http://www.holdenweb.com/




More information about the Python-list mailing list