【发布时间】:2016-03-26 02:30:59
【问题描述】:
TypeError: %: 'NoneType' 和 'tuple' 的操作数类型不受支持
我需要一个引用或图像来代替%s,但似乎不知道怎么做?
#!/usr/bin/python
import random
if __name__=="__main__":
print("Content-type: text/html")
print()
quotes=["The course of true love never did run smooth.", "Life every man holds dear; but the dear man holds honor far more precious dear than life.",
"To thine own self be true, and it must follow, as the night the day, thou canst not then be false to any man.", "Poor and content is rich, and rich enough.",
"If you have tears, prepare to shed them now.", "Words without thoughts never to heaven go."]
pics=["https://ebooks.adelaide.edu.au/s/shakespeare/william/portrait.jpg", "http://images.wisegeek.com/william-shakespeare-painting.jpg",
"https://mareseosullivan.files.wordpress.com/2012/01/william-shakespeare.jpg", "http://bookhaven.stanford.edu/wp-content/uploads/2010/10/shakespeare-4.jpg",
"http://i.telegraph.co.uk/multimedia/archive/02699/shakespeare_2699766b.jpg", "http://www.poetryfoundation.org/uploads/authors/william-shakespeare/448x/william-shakespeare.jpg"]
print ("""
<html>
<head>
<title>QOTD: Shakespeare </title>
</head>
<body>
<center>
<img src="%s">
<p>
<font size="12"><b>The quote of the day is:</b></font>
<p>
<table>
<tr>
<td width="500"><font size="6">%s</font>
</td>
</tr>
</table>
</p>
</center>
</body>
</html>
""") % (random.choice(pics), random.choice(quotes))
【问题讨论】:
-
@idjaw 我必须在此处更改缩进以使代码在我的问题中正确打印。你能告诉我你改变了什么吗?
-
我在 Python 2.7 上运行了您的代码。当我在 Python 3 上运行它时,我复制了你的问题。但是,您确实应该在问题中修正缩进,以便正确表示您的代码。
标签: python random tuples operands