[New-bugs-announce] [issue10129] Curious 'name not defined error' with 'python -m'

Andreas Kloeckner report at bugs.python.org
Sun Oct 17 05:42:27 CEST 2010


New submission from Andreas Kloeckner <inform at tiker.net>:

$ python3.1 -m a b.py

results in

Traceback (most recent call last):
  File "/usr/lib/python3.1/runpy.py", line 128, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python3.1/runpy.py", line 34, in _run_code
    exec(code, run_globals)
  File "/home/andreas/tmp/python-mbug/a.py", line 6, in <module>
    main()
  File "/home/andreas/tmp/python-mbug/a.py", line 3, in main
    exec(compile(open(sys.argv[1]).read(), sys.argv[1], 'exec'))
  File "b.py", line 8, in <module>
    sys.exit(main())
  File "b.py", line 5, in main
    argv = sys.argv[1:]
NameError: global name 'sys' is not defined

a.py --------------------------------------------------
def main():
    import sys
    exec(compile(open(sys.argv[1]).read(), sys.argv[1], 'exec'))

if __name__=='__main__':
    main()
-------------------------------------------------------

b.py --------------------------------------------------
import sys

def main():
  sys.argv[1:]

if __name__ == "__main__":
  main()
-------------------------------------------------------

----------
components: Interpreter Core
messages: 118913
nosy: inducer
priority: normal
severity: normal
status: open
title: Curious 'name not defined error' with 'python -m'
type: behavior
versions: Python 2.6, Python 3.1

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue10129>
_______________________________________


More information about the New-bugs-announce mailing list