Message101635
A friend wrote "exit(0)" in a script without an import of sys. I
pointed out the error and he said "But it works". He was right.
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 9.10
Release: 9.10
Codename: karmic
$ python --version
Python 2.6.4
$ python -c 'quit("foo")'
foo
$ echo $?
1
$ python -Sc 'quit("foo")'
Traceback (most recent call last):
File "<string>", line 1, in <module>
NameError: name 'quit' is not defined
$ python -c 'print quit.__class__, exit.__class__'
<class 'site.Quitter'> <class 'site.Quitter'>
$
site.py is polluting, to my mind, the builtin namespace with `exit' and
`quit'. Surely this should only happen for interactive use of python?
http://docs.python.org/library/constants.html#exit says "They are useful
for the interactive interpreter shell and should not be used in
programs." but it seems to easy for exit, especially, to be used by
mistake.
Could the pollution only happen if the Python interpreter is an
interactive one? Or, not as good, when called, could they tell this
isn't an interactive session and error? |
|
Date |
User |
Action |
Args |
2010-03-24 14:52:38 | ralph.corderoy | set | recipients:
+ ralph.corderoy |
2010-03-24 14:52:37 | ralph.corderoy | set | messageid: <1269442357.88.0.102314417571.issue8220@psf.upfronthosting.co.za> |
2010-03-24 14:52:36 | ralph.corderoy | link | issue8220 messages |
2010-03-24 14:52:35 | ralph.corderoy | create | |
|