【发布时间】:2015-05-14 12:13:05
【问题描述】:
我是 python 的初学者。我已经安装了 python34 和 xampp 1.8.0 并在 httpd.conf 中启用为 AddHandler cgi-script.cgi.pl.asp.py 从下面的简单代码开始;
#!"C:\python34\python.exe"
import cgitb
cgitb.enable()
print("Content-Type: text/html;charset=utf-8")
print ('Hello World \n')
print ( 'new world' )
print ('\n')
if ( 6 > 5) :
print ("greater")
并在本地主机中以http://localhost/cgi-bin/example.py执行此代码
输出为
Hello World 新世界更大
单词之间没有换行符。我错过了什么? 输出我需要的
Hello world
new world
greater
【问题讨论】:
-
我假设您正在浏览器中查看结果,但您不知道 HTML 是什么?查看页面的源代码,而不是渲染的页面。
-
你能具体解释一下吗
-
为什么打印 ('\n') 不起作用?
-
@user092,因为
'\n'是 shell、Python 或 C/C++ 字符,但绝对不是 HTML。如果要换行,请使用<br/>