By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,547 Members | 1,429 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,547 IT Pros & Developers. It's quick & easy.

\r\n problem in cgi module?

P: n/a
I'm wrote a cgi script which saves some data in a file, which is
POSTed from a HTML page.

The HTML page includes:

<textarea name="text" cols="80" rows="5"></textarea>

Then I extract the "text" as such:

f=cgi.FieldStorage()
text=f['text'].value

The surprise is "text" contains "\r\n" instead of "\n", when running
on windows.

Why does this happen, and what am I supposed to do? Isn't cgi module
supposed to provide "universal_new_line"?
Jul 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Jane Austine wrote:
The HTML page includes:

<textarea name="text" cols="80" rows="5"></textarea>

Then I extract the "text" as such:

f=cgi.FieldStorage()
text=f['text'].value

The surprise is "text" contains "\r\n" instead of "\n", when running
on windows.

Why does this happen, and what am I supposed to do? Isn't cgi module
supposed to provide "universal_new_line"?


CGI has a weird specification where textareas are supposed to be
delimited with CR LF, regardless of the platform. Weird, I know, but
the CGI module isn't wrong here.

--
__ Erik Max Francis && ma*@alcyone.com && http://www.alcyone.com/max/
/ \ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
\__/ Nobody can reach me, nobody can touch me; it's a wonderful
feeling. -- Aaliyah
Jul 18 '05 #2

P: n/a
Jane Austine wrote:
I'm wrote a cgi script which saves some data in a file, which is
POSTed from a HTML page.

The HTML page includes:

<textarea name="text" cols="80" rows="5"></textarea>

Then I extract the "text" as such:

f=cgi.FieldStorage()
text=f['text'].value

The surprise is "text" contains "\r\n" instead of "\n", when running
on windows.

Why does this happen, and what am I supposed to do? Isn't cgi module
supposed to provide "universal_new_line"?


And the shortest solution for you is

text = f['text'].value.replace('\r\n', '\n')

-Peter
Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.