I need newbie help

Sean Berry sean_berry at cox.net
Thu May 13 20:58:14 EDT 2004


"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
>
> --





More information about the Python-list mailing list