Paramaterized local variable name

Sean 'Shaleh' Perry shalehperry at attbi.com
Sun Dec 30 00:34:51 EST 2001


> 
> So, if local_name is equal to 'name' or 'rev' or 'whatever', what I
> want is something like:
> 
> def paging(data, key, query_dict, local_name):
>   for i in range(0, len(data[key]), use_pagesize):
>     start = data[key][i].
>#       What goes here   ^^^^  ?
> 

exec("start = data[key][i].%s" % local_name)

should do nicely I think.  Basically, create a line of python code and tell
python to execute it.  Works just as if the line was in your code.




More information about the Python-list mailing list