[Ironpython-users] IronPython, Daily Digest 7/1/2011

no_reply at codeplex.com no_reply at codeplex.com
Sat Jul 2 16:53:25 CEST 2011


Hi ironpython,

Here's your Daily Digest of new issues for project "IronPython".

In today's digest:ISSUES

1. [New issue] Scope is not remembered after an import
2. [New comment] Scope is not remembered after an import

----------------------------------------------

ISSUES

1. [New issue] Scope is not remembered after an import
http://ironpython.codeplex.com/workitem/30955
User WimVanLoocke has proposed the issue:

"When using ironpython to run py scripts, one creates in c# as scope for the engine, and sets a variable.

When running the .py file is executed and the scope is know.
When running a .py file that imports an other .py file( can contains ref to variable in the scope ) the variable is no longer know.

When looking into the code 

{ snipped }
internal PythonModule/*!*/ CompileModule(string fileName, string moduleName, SourceUnit sourceCode, ModuleOptions options, out ScriptCode scriptCode) {

ContractUtils.RequiresNotNull(fileName, "fileName");

ContractUtils.RequiresNotNull(moduleName, "moduleName");

ContractUtils.RequiresNotNull(sourceCode, "sourceCode");

scriptCode = GetScriptCode(sourceCode, moduleName, options);

Scope scope = scriptCode.CreateScope();

return InitializeModule(fileName, ((PythonScopeExtension)scope.GetExtension(ContextId)).ModuleContext, scriptCode, options);

}

{ end snipped }

you can see that a new scope is created, and not the initial scope is used.

Init :
_Engine = Python.CreateEngine();
scope = _Engine.CreateScope();
            scope.SetVariable("I2C", localEngine);
            scope.SetVariable("UART", Poderosa);
            scope.SetVariable("dbg", _txtOut);

            _txtBox.InteractiveObj.Add("I2C", localEngine);
            _txtBox.InteractiveObj.Add("UART", Poderosa);
            _txtBox.InteractiveObj.Add("dbg", _txtOut);

Execute

                _Engine.ExecuteFile(_PathToScript, scope);"-----------------

2. [New comment] Scope is not remembered after an import
http://ironpython.codeplex.com/workitem/30955
User slide_o_mix has commented on the issue:

"This doesn't work in CPython either. Each module has it's own scope:

foo.py:
print "x = %d" % x
def foo():
    x = globals()['x']
    print "x = %d" % x


script.py:
x = 5
import foo

foo.doit()


OUTPUT:
Traceback (most recent call last):
  File "C:\Python27\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 325, in RunScript
    exec codeObject in __main__.__dict__
  File "script.py", line 3, in <module>
    import foo
  File "foo.py", line 3, in <module>
    print "x = %d" % x
NameError: name 'x' is not defined


"
----------------------------------------------



----------------------------------------------
You are receiving this email because you subscribed to notifications on CodePlex.

To report a bug, request a feature, or add a comment, visit IronPython Issue Tracker. You can unsubscribe or change your issue notification settings on CodePlex.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20110702/7029ae3d/attachment.html>


More information about the Ironpython-users mailing list