file operations.
aditya shukla
adityashukla1983 at gmail.com
Thu Jul 24 18:46:41 EDT 2008
Guys thanks for your previous help .I have a doubt again
My text file is :-
0\9\10\11|0.50|c:\windows\apppatch/AcLayers.dll
0\9\10\11|0.50|c:\windows\apppatch/AcRedir.dll
0\9\10|0.66|c:\windows\apppatch/AcSpecfc.dll
0\9|0.83|c:\windows\apppatch/iebrshim.dll
0|0.92|c:\windows\apppatch/pcamain.sdb
0|0.92|c:\windows\apppatch/sysmain.sdb
0|0.93|c:\windows\apppatch/AcXtrnal.dll
0|0.97|c:\windows\apppatch/msimain.sdb
0|0.98|c:\windows\apppatch/AcRes.dll
0|0.98|c:\windows\apppatch/drvmain.sdb
0|0.98|c:\windows\apppatch/en-US/AcRes.dll.mui
0|0.99|c:\windows\apppatch/apihex86.dll
0|1.00|c:\windows\apppatch/AcGenral.dll
now this is what happens
>>> x=open("c:\\test2.txt","rb")
>>> x.readline()
'\n' ---? i am not able to understand why is new line character returned
here
>>> l =x.readline()
>>> print l
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:
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
Whereas the solution works well with the dummy text file which i have
created which is a.txt
jd|fj|dnv|jd|0.33|c:\\windows\\win32
shcbsbs|nscsjsj|0.93|hsbcjsnc
x=open("a.txt","r")
data=[]
for line in x:
line=line.split("|")
data.append(float(line[-2]))
print data
0.3300002,0.9300006
Please help me fix this problem
Thanks in advance
Aditya
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080724/f0fcd57e/attachment.html>
More information about the Python-list
mailing list