[Zope] Line breaks...

Richard Wesley hawkfish@electricfish.com
Wed, 10 Apr 2002 13:29:28 -0700


At 8:50 PM +0100 4/10/02, seb bacon wrote:
>Richard Wesley wrote:
>>Anyone have a reasonable technique for splitting uploaded files on 
>>line breaks? readlines will not work because the file might have a 
>>non-Unix EOL convention (e.g. Macintosh or DOS).
>
>surely readlines *will* work because python is x-platform ?!

It only works if the uploaded file has the same EOL convention as the 
server.  MacPython has no trouble with Mac files etc., but moving 
around between platforms is not supported.

What I wound up doing was:

f = <UploadFile>
d = f.read()
d = string.replace(d,"\r\n","\n")	# DOS => Local
d = string.replace(d,"\r","\n")         # Mac => Local
lines = string.split(d,"\n")		# Split on the local EOL

and the only problem is that the last line is blank.

- rmgw

http://www.electricfish.com/hawkfish/

----------------------------------------------------------------------------
Richard Wesley           Electric Fish, Inc.       hawkfish@electricfish.com

"You miss too much these days if you stop to think."
                   - U2, "Waiting for the End of the World"