469,360 Members | 1,774 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,360 developers. It's quick & easy.

'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!
Jul 18 '05 #1
6 1977
> 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

De*****@dair.com http://www.spamai.com?ng_py
Jul 18 '05 #2
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
Jul 18 '05 #3
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:TV****************@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."

Jul 18 '05 #4
"Andrew Chalk" <ac****@XXXmagnacartasoftware.com> wrote in message news:<ER**********************@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"
Jul 18 '05 #5
"Andrew Chalk" <ac****@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

print 'Hello'
print 'World'

--
Andrew Clover
mailto:an*@doxdesk.com
http://www.doxdesk.com/
Jul 18 '05 #6
dan
This is a random guess, but try:

print "Hello<br>"
print "World"

"Andrew Chalk" <ac****@XXXmagnacartasoftware.com> wrote in message news:<ER**********************@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!

Jul 18 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by Michael Foord | last post: by
14 posts views Thread by Marcin Ciura | last post: by
reply views Thread by bearophileHUGS | last post: by
1 post views Thread by Steff | last post: by
3 posts views Thread by James J. Besemer | last post: by
69 posts views Thread by Edward K Ream | last post: by
7 posts views Thread by samslists | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.