![]() |
'print' in a CGI app.
In a Python 2.2 app. running under CGI the statements
print "Hello\n" print "World" print both words on the same line in IE6. How do I print the second one on a new line (i.e. respect the \n in the first statement). Many thanks! |
Re: 'print' in a CGI app.
> print "Hello\n"
> print "World" Try print "Hello<br>\n" print "World" or try print "<pre>" print "Hello\n" print "World" print "</pre>" -- Dennis Reinhardt DennisR@dair.com http://www.spamai.com?ng_py |
Re: 'print' in a CGI app.
Andrew Chalk wrote:
> In a Python 2.2 app. running under CGI the statements > > print "Hello\n" > print "World" > > print both words on the same line in IE6. How do I print the second one on a > new line (i.e. respect the \n in the first statement). Umm. This has nothing to do with Python... but hey :-) Unless your CGI script is set to content-type: text/plain, you're supposed to print valid HTML. You'll have more success if you print the following: print "<html><body>" # begin HTML print "<pre>" # HTML 'preformatted' block print "Hello\n" print "World" print "</pre>" # end 'preformatted block' print "</body></html>" # end HTML --Irmen |
Re: 'print' in a CGI app.
Thanks to you, Timo, Dennis and Irmen. The <BR> trick was what I was using
but I thought I must be missing something. Regards "Timo Virkkala" <wt@nic.fi> wrote in message news:TVcXa.4487$HC4.642@reader1.news.jippii.net... > Andrew Chalk wrote: > > In a Python 2.2 app. running under CGI the statements > > > > print "Hello\n" > > print "World" > > > > print both words on the same line in IE6. How do I print the second one on a > > new line (i.e. respect the \n in the first statement). > > How about (untested): > > print "Hello<BR>\n" > print "World" > > ...since, AFAIK, it should be HTML that CGI's output...? > > -- > Timo Virkkala | wt@nic.fi > > "In the battle between you and the world, bet on the world." > |
Re: 'print' in a CGI app.
"Andrew Chalk" <achalk@XXXmagnacartasoftware.com> wrote in message news:<ERcXa.1902$W63.925904037@newssvr30.news.prod igy.com>...
> In a Python 2.2 app. running under CGI the statements > > print "Hello\n" > print "World" > > print both words on the same line in IE6. How do I print the second one on a > new line (i.e. respect the \n in the first statement). > > Many thanks! Run the app, then go to "View"->"Source" in the browser. $10 says they are on separate lines. All browsers are expecting HTML output from CGI scripts. HTML ignores whitespace. The <br> tag comes in handy for forcing an endline: print "Hello<br>" print "World" |
Re: 'print' in a CGI app.
"Andrew Chalk" <achalk@XXXmagnacartasoftware.com> wrote:
> print "Hello\n" > print "World" > print both words on the same line in IE6. This is because IE is treating the page as HTML by default, where whitespace is not significant. If this is not what you want, set the 'Content-Type' HTTP header to something else, eg.: #!/usr/bin/python print 'Content-Type: text/plain; charset=utf-8' print 'Hello' print 'World' -- Andrew Clover mailto:and@doxdesk.com http://www.doxdesk.com/ |
Re: 'print' in a CGI app.
This is a random guess, but try:
print "Hello<br>" print "World" "Andrew Chalk" <achalk@XXXmagnacartasoftware.com> wrote in message news:<ERcXa.1902$W63.925904037@newssvr30.news.prod igy.com>... > In a Python 2.2 app. running under CGI the statements > > print "Hello\n" > print "World" > > print both words on the same line in IE6. How do I print the second one on a > new line (i.e. respect the \n in the first statement). > > Many thanks! |
| All times are GMT. The time now is 05:08 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.