File Object behavior
Bruno Desthuilliers
bdesth.quelquechose at free.quelquepart.fr
Tue Apr 3 17:33:00 EDT 2007
Michael Castleton a écrit :
> When I open a csv or txt file with:
>
> infile = open(sys.argv[1],'rb').readlines()
> or
> infile = open(sys.argv[1],'rb').read()
>
> and then look at the first few lines of the file there is a carriage return
> +
> line feed at the end of each line - \r\n
Is there any reason you open your text files in binary mode ?
Unless you're using the csv module (which requires such a mode - but
then you don't care since you're not working with the raw data
yourself), you should consider opening your files in text mode. This
should solve your problem (if not, then you have a problem with
universal newlines support in your Python install).
HTH
More information about the Python-list
mailing list