|
|
Python: universal newlines with file from CGI?
|
|
|
|
Posting Junkie
Join Date: Jun 2001
Location: Baltimore, MD
Status:
Offline
|
|
I'm working on a Python CGI script that operates on an uploaded text file. I ran into a problem with a particular file, and experimenting with it at the command line has revealed that the only thing that seems to make it work properly is if I open the file in universal-newline mode (open(file, "U")). However since I'm getting the file from formdata, I have no idea how I could possibly use universal-newline mode with it. Extensive googling has revealed only other people asking the same question and getting no answer.
Does anyone here have any ideas?
|
|
|
|
|
|
|
|
|
Mac Elite
Join Date: Oct 1999
Location: San Jose, Ca
Status:
Offline
|
|
There are two basic solutions:
1) Write the data out to a temp file, and then open that.
2) Use regular expressions to make the newlines the way you want. You are probably looking at three combinations: windows (\r\n), old mac (\r), *nix (\n). You probably just want to convert everything to a single type (probably the last one). You want to probably start with the windows type when converting.
I am ignoring the Unicode returns, and the few other types, but that should probably get you where you want to go.
|
|
|
|
|
|
|
|
|
Posting Junkie
Join Date: Jun 2001
Location: Baltimore, MD
Status:
Offline
|
|
That's what I was afraid of.
Thanks.
|
|
|
|
|
|
|
|
|
Posting Junkie
Join Date: Jun 2001
Location: Baltimore, MD
Status:
Offline
|
|
Argh. After all that it turned out not to be a newline problem after all, but a user error from people who can't follow simple directions...
Apparently when reading from a CSV file, a row that has too few columns in it is (understandably) interpreted as a newline issue.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Forum Rules
|
|
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
|
|
|
|
|
|