@@ -18,7 +18,7 @@ Syntax errors, also known as parsing errors, are perhaps the most common kind of
1818complaint you get while you are still learning Python::
1919
2020 >>> while True print('Hello world')
21- File "<stdin>", line 1, in ?
21+ File "<stdin>", line 1
2222 while True print('Hello world')
2323 ^
2424 SyntaxError: invalid syntax
@@ -44,15 +44,15 @@ programs, however, and result in error messages as shown here::
4444
4545 >>> 10 * (1/0)
4646 Traceback (most recent call last):
47- File "<stdin>", line 1, in ?
47+ File "<stdin>", line 1, in <module>
4848 ZeroDivisionError: division by zero
4949 >>> 4 + spam*3
5050 Traceback (most recent call last):
51- File "<stdin>", line 1, in ?
51+ File "<stdin>", line 1, in <module>
5252 NameError: name 'spam' is not defined
5353 >>> '2' + 2
5454 Traceback (most recent call last):
55- File "<stdin>", line 1, in ?
55+ File "<stdin>", line 1, in <module>
5656 TypeError: Can't convert 'int' object to str implicitly
5757
5858The last line of the error message indicates what happened. Exceptions come in
@@ -214,7 +214,7 @@ exception to occur. For example::
214214
215215 >>> raise NameError('HiThere')
216216 Traceback (most recent call last):
217- File "<stdin>", line 1, in ?
217+ File "<stdin>", line 1, in <module>
218218 NameError: HiThere
219219
220220The sole argument to :keyword: `raise ` indicates the exception to be raised.
@@ -233,7 +233,7 @@ re-raise the exception::
233233 ...
234234 An exception flew by!
235235 Traceback (most recent call last):
236- File "<stdin>", line 2, in ?
236+ File "<stdin>", line 2, in <module>
237237 NameError: HiThere
238238
239239
@@ -308,7 +308,7 @@ example::
308308 ...
309309 Goodbye, world!
310310 Traceback (most recent call last):
311- File "<stdin>", line 2, in ?
311+ File "<stdin>", line 2, in <module>
312312 KeyboardInterrupt
313313
314314A *finally clause * is always executed before leaving the :keyword: `try `
@@ -340,7 +340,7 @@ complicated example::
340340 >>> divide("2", "1")
341341 executing finally clause
342342 Traceback (most recent call last):
343- File "<stdin>", line 1, in ?
343+ File "<stdin>", line 1, in <module>
344344 File "<stdin>", line 3, in divide
345345 TypeError: unsupported operand type(s) for /: 'str' and 'str'
346346
0 commit comments