IronPython 2.7A1 execute from file source throws method not implemented error
I am trying to call a python script from a windows executable, ultimately the goal is a windows service that I can plug various scripts into, for example to pull back email attachments (since python has good imap support). Of course, I am a total newb so I am clueless :) I get an unhandled exception:
System.NotImplementedException: The method or operation is not implemented. at Microsoft.Scripting.PlatformAdaptationLayer.O开发者_如何转开发penInputFileStream(String path)
and gobs more but that seems to be the key issue. Clearly this must have to do with reading the code from a file because the simple change below makes it work. I'm wondering if this is a bug in IP 2.7A1 but I think I would have found that in my hopefully exhaustive web search. Okay, here's the code:
var engine = Python.CreateEngine();
var script = engine.CreateScriptSourceFromFile("PyTest.py");
ScriptScope scope = engine.CreateScope();
script.Execute(scope);
and the PyTest.py code is very simple, an example from the web:
import sys
#def Main():
def adder(arg1, arg2):
return arg1 + arg2
class MyClass(object):
def __init__(self, value):
self.value = value
if I call that script by assigning it to a string value and using the CreateScriptSourceFromString method it works fine. I have verified that the code can see the PyTest.py file by doing a file.exists(fileName) and it sees the file. I also tried explicitly giving the path to no avail.
Thanks for any suggestions!
Are you sure you're using a build of IronPython which is for the .NET framework? The Silverlight builds (which will also load on the desktop framework) have filesystem stuff disabled. I can do this from a console .exe just fine, so please provide some more information.
精彩评论