set variable to looping index?

Bearophile bearophileHUGS at lycos.com
Wed Jul 29 17:12:34 EDT 2009


Martin:
> for f in var1_fn, var2_fn, var3_fn:
>     if f.split('.')[0] == 'var1':
>         var1 = call_some_function(f)
>         .
>         .
>         .
>       etc

As usual I have big problems in understanding what you want to do.

Please, show an example of the contents of var1_fn, var2_fn, etc.

Generally you can create a dict:
results = {}

And then fill it with name-result pairs:
name = value.split('_')[0]
results[name] = some_function(value)

Bye,
bearophile



More information about the Python-list mailing list