Formatting data to output in web browser from web form

John Machin sjmachin at lexicon.net
Sat Jul 9 07:58:04 EDT 2005


Harlin Seritt wrote:
> Hi,
> 
> I am using CherryPy to make a very small Blog web app.
> 
> Of course I use a textarea input on a page to get some information.
> Most of the time when text is entered into it, there will be carriage
> returns.
> 
> When I take the text and then try to re-write it out to output (in html
> on a web page), I notice the Python strings don't translate these
> special characters (carriage returns) to a "<p>" so that these
> paragraphs show up properly in html for output.  I tried doing something
> like StringData.replace('\n', '<p>'). Of course this doesnt work
> because it appears that '\n' is not being used.
> 
> Is there anything I can do to make sure paragraphs show up properly?
> 

The ASCII carriage return (CR) is represented in Python as "\x0d" or 
"\r". The line feed (LF) is "\x0a" or "\n". Does this info help you with 
your problem? If, not perhaps you might like to

print repr(StringData)

so that we can see what you are calling "carriage returns".

HTH,
John



More information about the Python-list mailing list