[Tutor] calling a variable name

Tino Dai tinoloc at gmail.com
Mon Oct 22 12:54:48 CEST 2007

On 10/21/07, Bryan Fodness <bryan.fodness at gmail.com> wrote:
> I want to get a variable name dependent on another variable.  I have
> tried,
> 'fs' + str(int(round(unblockedFS))) for fs13
> and I get an invalid literal.  If I code in the fs13, everything works. Is
> it possible to do this?
> unblockedFS=13.4
> for line in file('21Ex6MV_tmr.dat'):
>     d, fs1, fs2, fs3, fs4, fs5, fs6, fs7, fs8, fs9, fs10, fs11, fs12,
> fs13, fs14, fs15, fs16, fs17, fs18 = line.split()
>     if float(d) == round(calc_depth):
>         b = float( fs13)
>         print float(fs13)
> Thanks,
> Bryan

Hi Bryan,

      Have you thought about using a dictionary instead of slew of
variables? IHMO, that will cut down on the number of variables that you have
to juggle. So instead of
you would have

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20071022/4ee8cbc3/attachment.htm 

More information about the Tutor mailing list