\r\n problem in cgi module?
Peter Hansen
peter at engcorp.com
Sat Mar 20 17:40:06 EST 2004
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
More information about the Python-list
mailing list