New submission from anatoly techtonik <techto...@gmail.com>:

main.py below fails to execute local.py, which work ok (outputs '2') when 
processed directly in console.

Docs are not explaining anything. They spread fear and uncertainty around 
locals, but nothing is said why globals may fail.
http://docs.python.org/library/functions.html#execfile


---[cut main.py]---
values = {}
glavues = {}
execfile('local.py', glavues, values)
---[/cut]-----------

---[cut local.py]---
x = 1
def weird():
    y = x + 1
    return y
print weird()
---[/cut]-----------



Traceback (most recent call last):
  File "main.py", line 5, in <module>
    execfile('local.py', glavues, values)
  File "local.py", line 7, in <module>
    print weird()
  File "local.py", line 5, in weird
    y = x + 1
NameError: global name 'x' is not defined

----------
assignee: docs@python
components: Documentation, Library (Lib)
messages: 153643
nosy: docs@python, techtonik
priority: normal
severity: normal
status: open
title: execfile() fails on files that use global variables inside functions
versions: Python 2.7

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue14049>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to