Message277731
At https://docs.python.org/3.5/tutorial/errors.html#defining-clean-up-actions
when I'm running the "divide('2', '1')" example I get:
File "<stdin>", line 1, in <module>
instead of the documentation output of:
File "<stdin>", line 1, in ?
The same message is included with the 2.7 tutorial.
To wit:
$ python3
Python 3.5.2 (default, Sep 14 2016, 11:28:32)
[GCC 6.2.1 20160901 (Red Hat 6.2.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> def divide(x, y):
... try:
... result = x / y
... except ZeroDivisionError:
... print('division by zero!')
... else:
... print('result is', result)
... finally:
... print('executing finally clause')
...
>>> divide(2, 1)
result is 2.0
executing finally clause
>>> divide(2, 0)
division by zero!
executing finally clause
>>> divide('2', '1')
executing finally clause
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 3, in divide
TypeError: unsupported operand type(s) for /: 'str' and 'str'
$ python2
Python 2.7.12 (default, Sep 2 2016, 15:40:50)
[GCC 6.2.1 20160901 (Red Hat 6.2.1-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> def divide(x, y):
... result = x / y
KeyboardInterrupt
>>> def divide(x, y):
... try:
... result = x / y
... except ZeroDivisionError:
... print('division by zero!')
... else:
... print('result is', result)
... finally:
... print('executing finally clause')
...
>>> divide(2, 1)
('result is', 2)
executing finally clause
>>> divide(2, 0)
division by zero!
executing finally clause
>>> divide('2', '1')
executing finally clause
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 3, in divide
TypeError: unsupported operand type(s) for /: 'str' and 'str'
Nice tutorial by the way ;) Thanks! |
|
Date |
User |
Action |
Args |
2016-09-30 00:17:26 | viorel | set | recipients:
+ viorel, docs@python |
2016-09-30 00:17:25 | viorel | set | messageid: <1475194645.41.0.947079052008.issue28315@psf.upfronthosting.co.za> |
2016-09-30 00:17:24 | viorel | link | issue28315 messages |
2016-09-30 00:17:20 | viorel | create | |
|