ironpython

IronPython sys._getframe not found

自闭症网瘾萝莉.ら 提交于 2019-11-30 01:38:53
问题 I'm currently building a program in C# which will call functions in provided python script files. Some of these script files calls _getframe() in sys , which results in the error: System.MissingMemberException: 'module' object has no attribute '_getframe' (Since IronPython doesn't have _getframe activated by default.) I have done quite a lot of googling and found out that you can activate it in ipy.exe by providing -X:Frames as a command line option, however this doesn't solve my problem

IronPython and C# - Script Access to C# Objects

倖福魔咒の 提交于 2019-11-29 23:26:42
问题 Consider the code below: ScriptRuntimeSetup setup = Python.CreateRuntimeSetup(null); ScriptRuntime runtime = new ScriptRuntime(setup); ScriptEngine engine = Python.GetEngine(runtime); ScriptScope scope = engine.CreateScope(); scope.SetVariable("message", "Hello, world!"); string script = @"print message"; ScriptSource source = scope.Engine.CreateScriptSourceFromString(script, SourceCodeKind.Statements); source.Execute(); This code yields the following exception: Microsoft.Scripting.Runtime

Pure python implementation of greenlet API

限于喜欢 提交于 2019-11-29 20:29:19
The greenlet package is used by gevent and eventlet for asynchronous IO. It is written as a C-extension and therefore doesn't work with Jython or IronPython. If performance is of no concern, what is the easiest approach to implementing the greenlet API in pure Python. A simple example: def test1(): print 12 gr2.switch() print 34 def test2(): print 56 gr1.switch() print 78 gr1 = greenlet(test1) gr2 = greenlet(test2) gr1.switch() Should print 12, 56, 34 (and not 78). This kind of thing can be achieved with co-routines which have been built-in to the standard Python distribution since version 2.5

Can't use DateTime in IronPython

别来无恙 提交于 2019-11-29 19:56:43
问题 I'm hosting my IronPython in a C# webapp like so: var engine = Python.CreateEngine(); var scope = engine.CreateScope(); var script = Engine.CreateScriptSourceFromString(pythonCode, SourceCodeKind.Statements); script.Execute(scope); And my python code looks like this: import clr clr.AddReference('System.Core') from System import DateTime theDate = DateTime.Today() Which generates this error: IronPython.Runtime.Exceptions.ImportException: Cannot import name DateTime I've spent some time on

IronPython vs. Python .NET

半城伤御伤魂 提交于 2019-11-29 18:59:06
I want to access some .NET assemblies written in C# from Python code. A little research showed I have two choices: IronPython with .NET interface capability/support built-in Python with the Python .NET package What are the trade-offs between both solutions? Reed Copsey If you want to mainly base your code on the .NET framework, I'd highly recommend IronPython vs Python.NET. IronPython is pretty much native .NET - so it just works great when integrating with other .NET langauges. Python.NET is good if you want to just integrate one or two components from .NET into a standard python application.

Why do I get this .NET error - “TypeError: expected List[DataPoint], got List[DataPoint]”

拥有回忆 提交于 2019-11-29 17:59:45
I refactored some code, and now I get this error when calling a function. But everything seems to be fine, I even compared failing_argument.GetType().AssemblyQualifiedName between the old and the new code and they are the same. Any ideas what could be wrong? The invocation of the function is in IronPython code, the function is in C# code (an assembly which didn't change during this refactoring). What sort of thing could generate this error? EDIT: full IronPython traceback: Traceback (most recent call last): File "D:\Work\Framework\python\ide\tab_manager.py", line 57, in add_chart_tab chart_tab

How to host an IronPython engine in a separate AppDomain?

故事扮演 提交于 2019-11-29 15:27:02
问题 I have tried the obvious: var appDomain = AppDomain.CreateDomain("New Domain"); var engine = IronPython.Hosting.Python.CreateEngine(appDomain); // boom! But I am getting the following error message: Type is not resolved for member 'Microsoft.Scripting.Hosting.ScriptRuntimeSetup,Microsoft.Scripting, Version=0.9.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Googling for this error has not proved fruitful sofar... EDIT #1: I tried to create a minimal reproducing project by copying the

Instantiating custom C# classes from IronPython

随声附和 提交于 2019-11-29 15:11:52
问题 Is there any way to make a class available to IronPython scripts so that I can create objects inside the code? For example, if I have a class that I want to be able to instantiate from the script called MyClass defined in the C# code like so: public class MyClass { string text; public MyClass(string text) { this.text = text; } public void Write() { Console.WriteLine(text); } } How can I do this in the Python script? obj = MyClass("Hello, World!") obj.Write() Thanks! 回答1: Assuming MyClass is

How to embed IronPython in a .NET application

白昼怎懂夜的黑 提交于 2019-11-29 14:04:03
Is it possible to expose an API in a .NET application by embedding a scripting language like IronPython? How is it done? Srivatsn Narayanan IronPython has a hosting API which can be used to execute IronPython scripts from a C#\VB application. This is a good example of embedding IronPython inside a winforms app.Note that the hosting APIs have changed since that post. This post shows an example of the latest API You can find the latest specs here [Note: URL throws a 404 as of 2010-09-07] I haven't used it personally, but you should look at Visual Studio Tools for Applications I'm not sure if

How can I import a .PYD module in IronPython?

我的梦境 提交于 2019-11-29 12:51:26
I'm trying to use a python package from IronPython. Everything works fine if I import regular python modules. But when I try to do the following: import win32ui I get: No module named win32ui I've hunted through the code in IronPython.Runtime.Importer and there's no mention of .pyd Anyone know a way around this? You can check out IronClad which is working to provide this support. It may or may not work w/ your PYD of choice. A .pyd file is a DLL. So unless IronPython (which is written in .net) can correctly load C DLLs written for CPython, you might be out of luck. Update In fact, according to