a simple def how-to

John Posner jjposner at optimum.net
Sun Mar 7 16:23:35 CET 2010


On 3/7/2010 10:05 AM, vsoler wrote:
> Hello,
>
> My script starts like this:
>
> book=readFromExcelRange('book')
> house=readFromExcelRange('house')
> table=readFromExcelRange('table')
> read=readFromExcelRange('read')
> ...
>
> But I would like to have something equivalent, like...
>
> ranges=['book','house','table','read']
> for i in ranges:
>      var[i]=readFromExcelRange(i)
>
> which does not work. I assume I should be using globals() instead of
> var, but I do not know how to write my script.
>
> Can anybody help?

var = []    # create empty list
for i in ranges:
     var.append(readFromExcelRange(i))

  -or-

var = [ readFromExcelRange(i) for i in ranges ]

  -or-

var = map(readFromExcelRange, ranges)

-John



More information about the Python-list mailing list