最佳答案
How can I make a variable inside the try/except block public?
import urllib.request
try:
url = "http://www.google.com"
page = urllib.request.urlopen(url)
text = page.read().decode('utf8')
except (ValueError, RuntimeError, TypeError, NameError):
print("Unable to process your request dude!!")
print(text)
This code returns an error
NameError: name 'text' is not defined
How can I make the variable text available outside of the try/except block?