Tag: ironpython

访问Iron python中的.Net枚举

我正试图访问IronPython中的 .Net(C#)枚举,假设我们有 Test.dll的 // Contains Several Enums enum TestType{..} enum TestQuality{..} …. …. enum TestStatus{..} //Similarly Multiple functions public void StartTest(TestType testType, TestQuality testQuality){..} …. …. public TestStatus GetTestStatus(){..} 现在如果我尝试调用上面的函数,我需要选择适当的枚举参数,到目前为止我所做的是这个, 铁蟒[vs2012] import clr clr.AddReference(‘Test.dll’) from TestDll import * test = Test() # Initiate Enums enumTestType = TestType enumTestQuality = TestQuality …. …. enumTestStatus = TestStatus […]

在VisualStudio中创建IronPython项目时出错; “调用的目标引发了exception。”

我有一个解决方案,它将在C#中构建一个GUI,我想在解决方案中创建一个IronPython项目,该项目将从C#代码中调用,但我甚至无法创建它。 我正在使用CodePlex和IronPython 2.7中的python工具 编辑:这是我在ActivityLog.xml中找到的 System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. —> System.Reflection.TargetInvocationException: Failed to load language ‘IronPython 2.7.2.1’: Method not found: ‘!!1[] Microsoft.Scripting.Utils.ArrayUtils.ConvertAll(!!0[], System.Func 2)’. —> System.MissingMethodException: Method not found: ‘!!1[] Microsoft.Scripting.Utils.ArrayUtils.ConvertAll(!!0[], System.Func 2)’. at IronPython.Runtime.PythonContext..ctor(ScriptDomainManager manager, IDictionary 2 options) — End of inner exception stack trace — at Microsoft.Scripting.Runtime.LanguageConfiguration.LoadLanguageContext(ScriptDomainManager […]

.net框架与scrapy python

是否可以将.NET框架与Python scrapy框架一起使用来从不同站点获取数据? 我正在研究我的最后一年项目,我希望将C#用作前端语言,使用Python来抓取数据。

在C#中执行python脚本

我试图在C#中执行python代码。 通常应该使用IronPython并在安装PTVS之后完成(我使用的是VS 2010)。 var pyEngine = Python.CreateEngine(); var pyScope = pyEngine.CreateScope(); try { pyEngine.ExecuteFile(“plot.py”, pyScope); } catch (Exception ex) { Console.WriteLine(“There is a problem in your Python code: ” + ex.Message); } 问题是IronPython似乎无法识别像numpy,pylab或matplotlib这样的库。 我看了一下,发现有人在谈论Enthought Canopy或Anaconda,我已经安装了两个而没有解决问题。 我该怎么做才能解决问题?

C#/ IronPython Interop和“float”数据类型

使用一些IronPython脚本作为插件的项目,使用C#编码的function。 在我的一个C#类中,我有一个类型为的属性: Dictionary 我从IronPython代码中设置了该属性的值,如下所示: mc = MyClass() mc.ValueDictionary = Dictionary[int, float]({1:0.0, 2:0.012, 3:0.024}) 但是,当运行这段代码时,它会抛出以下exception: Microsoft.Scripting.ArgumentTypeException was unhandled by user code Message=expected Dictionary[int, Single], got Dictionary[int, float] 为了使事情变得更奇怪,最初使用的是C#代码 Dictionary 但是我在IronPython中找不到“双”类型,一想到就“浮动”并且工作正常,没有错误。 但是现在它在两端使用float(应该从一开始就使用它)它会出错,并且认为C#代码使用的是“Single”数据类型?! 我甚至在对象浏览器中检查了C#库,当然,它显示为使用“float”类型而不是“Single”

用ref或out参数编写铁python方法

我需要将以下C#方法转换为相同的IronPhyton方法 private void GetTP(string name, out string ter, out int prov) { ter = 2; prov = 1; }

在IronPython中访问C#类成员

在我的C#代码中,我有一个类,它存储了一些我希望传递给List中的python代码的数据。 但是,当我尝试在我的python代码中访问该类的属性时,我得到MissingMemberException 。 这里有一些示例代码来显示我的意思: C#: class Event { public int EventId { get; set; } public string EventName { get; set; } } //other processing here… //this just fills the list with event objects List eventList = GetEvents(); //this sets a variable in the ScriptScope PythonEngine.SetVariable( “events”, eventList); PythonEngine.Execute(“eventParser.py”); eventParser.py: for e in events: print […]

随机串c#

我想知道随机串 示例字符串 string word; //I want to shuffle it word = “hello” 我能得到: rand == “ohlel” rand == “lleho” etc.

有没有办法用Visual Studio和PTVS调试嵌入在C#中的Python代码?

我已经创建了在C#中嵌入IronPython代码的代码 public ScriptEngine GetEngine() { if( _engine != null ) return _engine; _engine = Python.CreateEngine(); var paths = _engine.GetSearchPaths(); paths.Add( _pythonPath ); _engine.SetSearchPaths( paths ); var runtime = _engine.Runtime; runtime.LoadAssembly( typeof( CharacterCore ).Assembly ); return _engine; } public IAbility Movement() { var engine = GetEngine(); var script = engine.CreateScriptSourceFromFile( Path.Combine( _pythonPath, “movement.py” ) ); var […]

在C#应用程序中嵌入IronPython – 在urllib上导入错误

我有一个包含as内容的Python文件: import re import urllib class A(object): def __init__(self, x): self.x = x def getVal(self): return self.x def __str__(self): return “instance of A with value ‘%s'” % (self.getVal()) 我还有一个简单的C#控制台项目,代码如下: engine = Python.CreateEngine(); ScriptSource source = engine.CreateScriptSourceFromFile(“test.py”); ScriptScope scope = engine.CreateScope(); ObjectOperations op = engine.Operations; source.Execute(scope); // class object created object klaz = scope.GetVariable(“A”); // get […]