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))
答案 0 :(得分:1)
你可能正在使用python 3.X.您使用的代码适用于python 2.X,但您需要按如下方式更改它:
而不是:
print (s) % (x, y)
试试这个:
print (s % (x, y))