【发布时间】:2014-06-14 17:06:10
【问题描述】:
我使用 python 编写了以下代码,我希望输出在控制台、文本和 html 中 html输出中的问题,在下面的输出中,有两列第一列是键,另一列是控制台中的值,文本之间有空格,但在html中没有空格
print f
x = "John"
g = "Peter"
if re.search(x,f) :
print temp.format("It contains John",2)
if re.search(g,f):
print temp.format("It contains Peter",5)
if re.search(x,f) and re.search(g,f):
print "It contains both persons"
sys.stdout = save_stdout
print capture.getvalue()
template = """
<html>
<head></head>
<body>
<p>%(text)s</p>
</body>
</html>
"""
count = capture.getvalue().count('\n')-1
html_message = template %{"text":capture.getvalue().replace('\n', "<br>\n", count)}
f2.write(html_message+"\n")
f2.close()
f1.write(capture.getvalue())
f1.close()
================================================ ================================
input : "Peter and John went to London"
output in console:
Peter and John went to London
It contains John 2
It contains Peter 5
It contains both persons
but in html:
Peter and John went to London
It contains John 2
It contains Peter 5
It contains both persons
在 html 的输出中没有像 console 和 text 这样的空格。 谁能帮我解决这个问题?
【问题讨论】:
-
HTML 需要特别小心才能生成列。控制台使用固定宽度字体,因此列就像确定必要的空格数一样简单。有几种方法可以在 HTML 中生成列,因此请研究并选择最适合您情况的方法。