file operations.

Fredrik Lundh fredrik at
Fri Jul 25 09:57:58 CEST 2008

aditya shukla wrote:

> Guys thanks for your previous help .I have a doubt again

(I'm sure you mean "a question"; in english, "a doubt" is something 
slightly different, and quite often more negative.)

> Also , because of this i am not able to extract the floating point 
> values ie 0.50,0.50,0.66 respectively
> cause when i use the proposed solution given earlier
> data=[]
> for line in x:

      print repr(line) # added for debugging!

>    line=line.split("|")
>    data.append(float(line[-2])) --> i am trying to get the floating 
> point values from the back
> i receive this error message
> Traceback (most recent call last):
>   File "<pyshell#71>", line 3, in <module>
>     d.append(float(line[-2]))
> IndexError: list index out of range

one or more lines in your file doesn't match the description; try adding 
a print statement (see above) to see what they might look like, and make 
sure that you filter them out (e.g. by checking the size of the list you 
get from the split, as Terry explains).


More information about the Python-list mailing list