tags:

views:

376

answers:

3

I know this question may well be the silliest question you've heard today, but to me it is a big question at this stage of my programming learning.

Why is the second empty line needed in this Python code? What does that line do?

print 'Content-Type: text/plain'
print ''
print 'Hello, world!'
+3  A: 

It prints an empty line, just as you have said. It will leave a blank line in the output. The print statement prints its arguments, and then a newline, so this prints just a newline.

You could accomplish the same thing with just:

print
Ned Batchelder
Thank You, Ned!!!!
brilliant
+1  A: 

Did you even tried to telnet web-server? It needs \n. So, it's what it does, you can write it in one line if needed.

print 'Content-Type: text/plain\n\nHello World'
confiq
it needs a blank line, you would need another `\n`
Carson Myers
That's right, fixed!Thanks!
confiq
~h-launchpad-net-c, what do You mean by "to telnet web-server"?
brilliant
If you telnet port 80 any web server, you will notice that delimiter between commands is "\n"
confiq
@ ~h-launchpad-net-c:What does this verb "to telnet" mean? How do You telnet port 80? I am sorry I am not a native English speaker and I am just a newbie in programming.
brilliant
try to write in terminal$telnet google 80They write GET /more info: http://forums.macosxhints.com/archive/index.php/t-10195.html
confiq
@ confiq:Hello, confiq!!! Which terminal do you mean? Is it that black window (its title is "C:\Python25\python.exe" without quotes) that opens up after I type "google_appengine/dev_appserver.py helloworld/" into command prompt? If yes, then I simply can't type anything in there. The cursor is still flashing under the last line (which is "myfirstapplicationsuniquename on port 8080: http://localhost:8080" without quotes), but when I try to type, nothing changes in that black window.
brilliant
@ confiq: Also, the link that You gave me seems to be for Linuix, but my computer is Windows, is it okay?
brilliant
Well, telnet is program that works in CLI (terminal). Try "Start" then RUN and then type "cmd"I don't use windows for ages...
confiq
@ confiq:Thank You, confiq!!!
brilliant
@ confiq: Hello, confiq!!! When I type "$telnet google 80 GET" or "$telnet google 80" or "$telnet google 80 GET/" and press "Enter", I get a line saying that '$telnet' "is neither an external nor internal command, thus, it can't followed upon" (this is my translation of that line from Chinese - I am right now in Taiwan, computer has Chinese platform, so those lines come in Chinese characters). Do you have any idea what that would mean?
brilliant
For the newest windows versions you have to install it from the windows software control panel. Its called "Telnet Client".
ZeissS
RF2616 seems to suggest that CRLF is required http://www.rfc-editor.org/rfc/rfc2616.txt
David Sykes
so interesting the question and the answers are~~ great~
ladyfafa
+4  A: 

A blank line is required between the headers and the body in an HTTP response, so a CGI script will print a blank line at just that spot. There's no need for the quotes though, since an unadorned print will output a blank line.

Ignacio Vazquez-Abrams