473,396 Members | 1,918 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 2192
> 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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.