I need newbie help
john fabiani
jfabiani at yolo.com
Fri May 14 00:35:49 EDT 2004
Sean Berry wrote:
> "Joseph Davidson" <jhd at radix.net> wrote in message
> news:10a83t8qku40d44 at corp.supernews.com...
>
>>I am an experienced perl programmer learning python ( no commente please
>>).
>>
>>In looking at a sample script at
>>http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/269708
>>
>>I found the following code snippet.
>>--------------------------------------------------
>>location = 'myHome'
>>fileLocation = {'myHome' :path1,
>> 'myOffice' :path2,
>> 'somewhere':path3}[location]
>>
>>-----------------------------------------------------
>>
>
>
> fileLocation takes the 'value' of the 'key' "location"
> equilvalent to:
>
> location = 'myHome'
> files = {'myHome' :path1, 'myOffice' :path2, 'somewhere':path3}
> fileLocation = files[location]
>
>
>>It seems that this is setting up fileLocation as a dictionary, but what
>>is the "[location]" doing?
>>
>>Joe Davidson
>>
>>--
>
>
>
I'm also a newbie. Did the programmer that wrote the code not use your
way (3 statements) because his statement was faster or because it better
python?
John
More information about the Python-list
mailing list