another question

Leeds, Mark mleeds at mlp.com
Thu Jun 5 17:43:37 EDT 2003


i'm sorry to bother everyone again :
 
i am a novice at python and i am
reading a file into memory
using the command
file.readlines.
 
the file has spaces between the elements but the delimiter that really
separates
them  is a "|".
 
so i wrote the subroutine below.
 
def getData(file):
 
    anyFile=open(file,'r')
    anyStuff=anyfile.readlines()
    anyFile.close
 
    anydata=[]
 
    for line in anyStuff:
        if not line:
            continue
        line=string.strip(line)
        anydata.append(string.split(line))
    return(anydata)
 
#-----------------------------------------------------------------------
------------------------------------------
 
in the main, i have
 
textfile=("xxx.dat")
datafile=getData(textfile))
print(datafile)
 
the problem is that i don't know how to get rid of the
"|" characters so these show up in the output.
 
if i use a parameter in string.split, then i will end up with spaces
which i don't want either.
 
i guess the question is how to get rid of both the spaces
and the "|" characters. 
 
                                                thanks.
 
 
 
 
 
 
 
 
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20030605/891bd4c4/attachment.html>


More information about the Python-list mailing list