[Tutor] calling a variable name

Evert Rol evert.rol at gmail.com
Mon Oct 22 14:06:18 CEST 2007


>> Here is the actual snippet of code
>>
>>
>> calc_depth =    8.1         # which is actually d
>> unblockedFS =   13.4     # which is the indexed fs
>>
>> 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, fs19, fs20, fs21, fs22, fs23,  
>> fs24,
>> fs25, fs26, fs27, fs28, fs29, fs30, fs31, fs32, fs33, fs34, fs35,  
>> fs36,
>> fs37, fs38, fs39, fs40 = line.split()
>>     if float(d) == round(calc_depth):
>>         print float('fs' + str(int(round(unblockedFS))))

Totally beside the point, but isn't it a bad idea in general to  
compare two floats like that? It'll probably work, thanks to the  
round function I guess (although shouldn't then 'float(d)' also be  
rounded?), but I would have compared for a minimal difference between  
two floats.





More information about the Tutor mailing list