Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   'print' in a CGI app. (http://www.velocityreviews.com/forums/t320509-print-in-a-cgi-app.html)

Andrew Chalk 08-03-2003 06:52 PM

'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!



Dennis Reinhardt 08-03-2003 07:02 PM

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



Irmen de Jong 08-03-2003 07:03 PM

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



Andrew Chalk 08-03-2003 07:50 PM

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."
>




Patrick Lioi 08-03-2003 09:30 PM

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"

Andrew Clover 08-03-2003 10:05 PM

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

print 'Hello'
print 'World'

--
Andrew Clover
mailto:and@doxdesk.com
http://www.doxdesk.com/

dan 08-03-2003 11:36 PM

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 04:00 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.