about try and exception

Ben Bush pythonnew at gmail.com
Thu Nov 17 19:21:00 EST 2005


I wrote the following code to test the use of "try...exception",
and I want n to be printed out. However, the following code's output is:
Traceback (most recent call last):
File
"C:\Python23\lib\site-packages\Pythonwin\pywin\framework\scriptutils.py",
line 310, in RunScript
exec codeObject in __main__.__dict__
File "C:\py\use\tryExVa.py", line 7, in ?
print n
NameError: name 'n' is not defined
 the code is here:
 try:
m=2/0
n=1/2
except ZeroDivisionError:
pass
print "Yes!!! This line will always print"
print n
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20051117/2dd797d6/attachment.html>


More information about the Python-list mailing list