[newbie] problem with data (different behaviour between batch and interactive use)
Justin Barber
barber.justin at gmail.com
Wed Jun 27 10:09:52 EDT 2012
When you are reading it in measurement is a string. The indicies of the string are going to be returned in your print statements.
Similar to having done this in the interpreter:
In [17]: measurement = '+3.874693E01,+9.999889E03,+9.910000E+37,+1.876595E+04,+3.994000E+04'
In [18]: measurement[1]
Out[18]: '3'
In [19]: measurement[0]
Out[19]: '+'
You need to split up your string and convert to floats.
measurement = map(float, serkeith.readline().replace('\x11','').replace('\x13','').replace('\x0d','\n').split(','))
Something like that should work...
to test in interpreter do the following :
measurement = map(float, '+3.874693E01,+9.999889E03,+9.910000E+37,+1.876595E+04,+3.994000E+04'.split(','))
In [24]: measurement[0]
Out[24]: 38.74693
More information about the Python-list
mailing list