retaining newline characters when writing to file

John Salerno johnjsal at NOSPAMgmail.com
Tue Jun 6 10:51:35 EDT 2006


If I read a string that contains a newline character(s) into a variable, 
then write that variable to a file, how can I retain those newline 
characters so that the string remains on one line rather than spans 
multiple lines?

Example: In a CGI script, I'm reading the address field from an HTML 
form. Almost always the person will press ENTER so they can enter a 
second or third line. If I then want to write all the field values of 
this form to a CSV file, so that each person's entries takes one line, 
how can I ensure that the address string stays on one line despite the 
newline characters?

(Or is it better to just use separate text fields for each line of the 
address?)

Thanks.



More information about the Python-list mailing list