ironpython

How do I set an IronPython ctypes c_char_p pointer to an absolute address manually?

感情迁移 提交于 2019-12-11 15:39:35
问题 I need to set the address to which a character pointer points to as an absolute value. In many Python implementations (CPyhton 2.x, CPython 3.x, PyPy & ActivePython, ...) this can be done using: >>> c_char_p(0xcafebabe) c_char_p(3405691582) >>> in IronPython: >>> c_char_p(0xcafebabe) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: expected char pointer, got long >>> IronPython does not attempt to set the address of the pointer, but treats the argument as

How to create IDLE -like functionality to WinForms application

本秂侑毒 提交于 2019-12-11 15:13:48
问题 I'd like to add "IDLE-like functionality" to C# WinForms application, but I don't quite have an idea how to do that and couldn't find anything useful with Google. So basically I want interactive command line interface, where user could enter some Python code and execute it (not just expressions, should be possible to define new functions). So, where to start? Are there any good tutorials or samples available? 回答1: If my memory serves me correctly there's a chapter on embedding Python in the

Iron python: How to append string to bytearray

坚强是说给别人听的谎言 提交于 2019-12-11 13:44:48
问题 I have a bytearray to which I have to add a number as a four character string. i.g. 14 should be added as '0014'. I tried this: id = 14 arr.append(bytearray(format(id, '04x'))) but it results in: TypeError: unicode argument without an encoding 回答1: Really you should explicitly specify the encoding when converting to bytes from a string. This answer also works in python 3: arr.extend(format(id, "04x").encode('ascii')) 回答2: arr.extend(bytes(format(id,"04x"))) 来源: https://stackoverflow.com

How can I use requests with Ironpython?

让人想犯罪 __ 提交于 2019-12-11 12:48:05
问题 I'm trying to run a script that was written with python 2.7, using some libraries that I've installed on my Windows machine - among them numpy scipy, scikit, requests and others. Now I need to use a COM object dll, so I am writing an IronPython script that loads that dll. However when I try to use or import the python 2.7 code, I get import errors: ImportError: No module named requests How can I use that python 2.7 code I wrote with IronPython? I could run the script with the python 2.7

How to create a new MSMQ message in IronPython with label, reply queue and other properties

可紊 提交于 2019-12-11 12:42:51
问题 I'm following this example here to use MS Message Queues with IronPython. The example works to create a message text string without any properties. import clr clr.AddReference('System.Messaging') from System.Messaging import MessageQueue ourQueue = '.\\private$\\myqueue' queue = MessageQueue(ourQueue) queue.Send('Hello from IronPython') I am trying to create an empty message and then add properties (like label, a reply queue and a binary message body) and then send that complete message. How

Python Tools for Visual Studio can't download `setuptools` on IronPython

落爺英雄遲暮 提交于 2019-12-11 11:50:36
问题 I'm using PTVS 2.1 with IronPython 2.7.4 in Visual Studio Express 2013 for Windows Desktop with Update 3 on a Windows 8.1 Pro x64 host with .NET 4.5 installed. I have an empty Python project with default env set to IronPython 2.7 . When I want to a virtual environment to the project PTVS tries to download setuptools and pip and fails miserably. The full log of the operation is here. In a gist it fails with: System.IO.IOException "Authentication failed because the remote party has closed the

IronPython call method by name

不打扰是莪最后的温柔 提交于 2019-12-11 11:16:47
问题 Is there any way to call method by name and specify arguments without using dynamic? (C#) UPDATE: ` public class Program { public static void Main(string[] args) { ScriptEngine engine = Python.CreateEngine(); ScriptScope scope = engine.CreateScope(); engine.ExecuteFile("script.py", scope); dynamic calculator = scope.GetVariable("Calculator"); dynamic calculatorInstance = engine.Operations.CreateInstance(calculator); dynamic result = engine.Operations.InvokeMember(calculatorInstance, "sample")

Install numpy for IronPython

99封情书 提交于 2019-12-11 09:54:57
问题 I wanted to run some code in IronPython using c#. In this code I needed to use numpy. So I tried to install it using the command below: ipy -X:Frames -m pip install -U numpy Unfortunately, I get an error and a return message telling me it was a unsuccessful installation. The error message is bellow: Using cached https://files.pythonhosted.org/packages/3a/20/c81632328b1a4e1db65f45c0a1350a9c5341fd4bbb8ea66cdd98da56fe2e/numpy-1.15.0.zip Installing collected packages: numpy Running setup.py

An example of ctypes on IronPython?

大兔子大兔子 提交于 2019-12-11 09:18:58
问题 I'm trying to understand ctypes, and it's relationship to IronClad, on IronPython. (Ctypes is supposed to be implemented in the latest IronPython release.) Can somebody give a simple example of ctypes in IronPython that works on Mono/OSX? When trying the standard demos, I get: import ctypes SystemError: libdl.so Am I missing something obvious? More generally, how does ctypes relate to the IronClad project? 回答1: I don't know the answer to your first question (I don't use Mono - sorry), but I

Terminating an IronPython script

折月煮酒 提交于 2019-12-11 08:17:40
问题 This may not specifically be an IronPython question, so a Python dev out there might be able to assist. I want to run python scripts in my .Net desktop app using IronPython, and would like to give users the ability to forcibly terminate a script. Here's my test script (I'm new to Python so it might not be totally correct):- import atexit import time import sys @atexit.register def cleanup(): print 'doing cleanup/termination code' sys.exit() for i in range(100): print 'doing something' time