another question

Juha Autero Juha.Autero at iki.fi
Fri Jun 6 02:18:58 EDT 2003


"Leeds, Mark" <mleeds at mlp.com> writes:

> i guess the question is how to get rid of both the spaces
> and the "|" characters. 

Why not strip the splited strings? 

def readfile(filename):
    filedata=[]
    for line in file(filename):
        if line:
            filedata.append([field.strip() for field in line.split("|")])
    return filedata

Or using your original code change
        anydata.append(string.split(line))
to
        anydata.append(map(string.strip,string.split(line,"|")))
-- 
Juha Autero
http://www.iki.fi/jautero/
Eschew obscurity!






More information about the Python-list mailing list