[Tutor] Initialize values from a text input file
Tim Johnson
tim at johnsons-web.com
Tue Jan 4 01:16:03 CET 2011
* Alan Gauld <alan.gauld at btinternet.com> [110103 14:47]:
>
> "Tim Johnson" <tim at johnsons-web.com> wrote
>
>> consider the following console session:
>>>>> L = ['foo','bar']
>>>>> locals()[L[0]] = L[1]
>>>>> foo
>> 'bar'
>>>>> locals()
>> {'__builtins__': <module '__builtin__' (built-in)>, 'L': ['foo',
>> 'bar'], '__package__': None, '__name__': '__main__', 'foo': 'bar',
>> '__doc__': None}
>>
>> I could initialize variables in a local scope, or I could build a
>> dictionary. Actually the dictionary is preferable for the targeted
>> application.
Actually, the dictionary is the target medium
> Except in extreme cases I'd say a dictionary was better in almost any
> situation. Messing with locals() is a dodgy business at best, and can
> lead to debugging insanity at worst, its better to keep externally
> initialized data explicit in almost every case.
I agree, that's why I said I "was having a little fun".
Now, Alan, do you know anything about PHP? If you do, can you
comment on the PHP extract() function?
thanks
--
Tim
tim at johnsons-web.com or akwebsoft.com
http://www.akwebsoft.com
More information about the Tutor
mailing list