472,374 Members | 1,488 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,374 software developers and data experts.

'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 2101
> 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Michael Foord | last post by:
Here's a little oddity with 'print' being a reserved word... >>> class thing: pass >>> something = thing() >>> something.print = 3 SyntaxError: invalid syntax >>> print something.__dict__...
14
by: Marcin Ciura | last post by:
Here is a pre-PEP about print that I wrote recently. Please let me know what is the community's opinion on it. Cheers, Marcin PEP: XXX Title: Print Without Intervening Space Version:...
0
by: bearophileHUGS | last post by:
There is/was a long discussion about the replacement for print in Python 3.0 (I don't know if this discussion is finished): http://mail.python.org/pipermail/python-dev/2005-September/055968.html ...
1
by: hamil | last post by:
I am trying to print a graphic file (tif) and also use the PrintPreview control, the PageSetup control, and the Print dialog control. The code attached is a concatination of two examples taken out...
1
by: Steff | last post by:
I am wandering if my code is making sense... I use a lot the print function. Is it weird in this case where I have to display an array ? I thought it would be better to have the entire array in php...
3
by: James J. Besemer | last post by:
I would like to champion a proposed enhancement to Python. I describe the basic idea below, in order to gage community interest. Right now, it's only an idea, and I'm sure there's room for...
69
by: Edward K Ream | last post by:
The pros and cons of making 'print' a function in Python 3.x are well discussed at: http://mail.python.org/pipermail/python-dev/2005-September/056154.html Alas, it appears that the effect of...
2
by: Brad Pears | last post by:
I have some sample code that uses the print dialog, print preview and a print direct options. If I select print preview and then click the printer icon from that, the document prints. If I...
7
by: samslists | last post by:
Am I the only one that thinks this would be useful? :) I'd really like to be able to use python 3.0's print statement in 2.x. Is this at least being considered as an option for 2.6? It seems...
12
by: Studiotyphoon | last post by:
Hi, I have report which I need to print 3 times, but would like to have the following headings Customer Copy - Print 1 Accounts Copy - Print 2 File Copy -Print 3 I created a macro to...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.
0
DizelArs
by: DizelArs | last post by:
Hi all) Faced with a problem, element.click() event doesn't work in Safari browser. Tried various tricks like emulating touch event through a function: let clickEvent = new Event('click', {...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.