我有行之有效以下Python代码:的Python如果在try和除其他
try:
with urlopen("http://my.domain.com/get.php?id=" + id) as response:
print("Has content" if response.read(1) else "Empty - no content")
except:
print("URL Error has occurred")
但是我想在try内的if else语句改变这样的:让我能运行额外的代码,而不是仅仅显示一条消息
try:
with urlopen("http://my.domain.com/get.php?id=" + id) as response:
if response.read(1):
print("Has content")
else:
print("Empty - no content")
except:
print("URL Error has occurred")
但上面不工作,给人以缩进
任何想法有什么不对相关的错误?
尝试删除try-except块并运行try:语句后面的代码。你会看到有什么问题。 – leeladam
你错过了“有内容” – njzk2
的引号,定义'not working' – njzk2