Author techtonik
Recipients docs@python, techtonik
Date 2012-02-18.12:59:57
SpamBayes Score 3.96444e-06
Marked as misclassified No
Message-id <1329569998.87.0.931536345344.issue14049@psf.upfronthosting.co.za>
In-reply-to
Content
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
History
Date User Action Args
2012-02-18 12:59:58techtoniksetrecipients: + techtonik, docs@python
2012-02-18 12:59:58techtoniksetmessageid: <1329569998.87.0.931536345344.issue14049@psf.upfronthosting.co.za>
2012-02-18 12:59:58techtoniklinkissue14049 messages
2012-02-18 12:59:57techtonikcreate