我有行之有效以下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