[IronPython] from __future__ import ...
Lukas Cenovsky
cenovsky at bakalari.cz
Mon Dec 14 11:18:36 CET 2009
Hi,
I've found that the from __future__ import ... works in .py file run by
ipy.exe but not when I create an engine in C#.
test.py:
from __future__ import division
print 'done'
test.cs:
using Microsoft.Scripting;
using Microsoft.Scripting.Hosting;
using IronPython.Hosting;
namespace TestDuture
{
public class Test
{
static void Main(string[] args)
{
ScriptEngine engine = Python.CreateEngine();
ScriptRuntime runtime = engine.Runtime;
ScriptScope scope = runtime.CreateScope();
ScriptSource source =
engine.CreateScriptSourceFromFile("test.py");
source.Execute(scope);
}
}
}
build command:
csc /r:Microsoft.Dynamic.dll /r:Microsoft.Scripting.core.dll
/r:Microsoft.Scripting.dll /r:IronPython.dll /r:IronPython.Modules.dll
test.cs
Running test.exe throws exception:
C:\Users\dev\Documents\FutureTest>test.exe
Unhandled Exception: IronPython.Runtime.Exceptions.ImportException: No
module named __future__
at
Microsoft.Scripting.Actions.Calls.MethodCandidate.Caller.Call(Object[]
args, Boolean& shouldOptimize)
at
IronPython.Runtime.Types.BuiltinFunction.BuiltinFunctionCaller`5.Call4(CallSite
site, CodeContext context, TFuncType func, T0 arg0, T1 arg1, T2 arg2, T3
arg3)
at
System.Dynamic.UpdateDelegates.UpdateAndExecute6[T0,T1,T2,T3,T4,T5,TRet](CallSite
site, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5)
at IronPython.Runtime.Importer.Import(CodeContext context, String
fullName, PythonTuple from, Int32 level)
at
IronPython.Runtime.Operations.PythonOps.ImportWithNames(CodeContext
context, String fullName, String[] names, Int32 level)
at Microsoft.Scripting.Utils.InvokeHelper`5.Invoke(Object arg0,
Object arg1, Object arg2, Object arg3)
at Microsoft.Scripting.Utils.ReflectedCaller.Invoke(Object[] args)
at
Microsoft.Scripting.Interpreter.CallInstruction.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame
frame)
at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0
arg0, T1 arg1)
at IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx)
at IronPython.Compiler.PythonScriptCode.Run(Scope scope)
at IronPython.Compiler.RuntimeScriptCode.InvokeTarget(Scope scope)
at IronPython.Compiler.RuntimeScriptCode.Run(Scope scope)
at Microsoft.Scripting.SourceUnit.Execute(Scope scope, ErrorSink
errorSink)
at Microsoft.Scripting.Hosting.ScriptSource.Execute(ScriptScope scope)
at TestDuture.Test.Main(String[] args)
Am I missing something? It works ok when I add __future__.py from Python
2.6.
--
-- Lukáš
More information about the Ironpython-users
mailing list