Re: Reading a file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Fredrik Lundh

    #1

    Re: Reading a file

    aditya shukla wrote:
    I have a text file whose contents are like this:-
    >
    jd|fj|dnv|jd|0. 33|c:\\windows\ \win32
    shcbsbs|nscsjsj |0.93|hsbcjsnc
    >
    I am trying to read the file like this:-
    >
    >>x = open("c:\\a.txt ","r")
    >>x.read()
    eh, wouldn't it be easier if you actually read the replies to your last
    post on this topic? here's an excerpt from the reply you got last time:
    Extracting is easy; you can do something like
    >
    data = []
    for line in open("test.txt" ):
    line = line.split("|")
    data.append(flo at(line[1]))
    which fetches floating point values from the text file example you
    posted last time:
    0\9\10\11|0.50| c:\windows\appp atch/AcLayers.dll
    0\9\10\11|0.50| c:\windows\appp atch/AcRedir.dll
    0\9\10|0.66|c:\ windows\apppatc h/AcSpecfc.dll
    0\9|0.83|c:\win dows\apppatch/iebrshim.dll
    if the values have moved to some other column, adjust line[1] accordingly.

    </F>

Working...