ironpython

Assigning a Iron Python list to .NET array

前提是你 提交于 2019-12-21 17:50:31
问题 I have a list comprehension operating on elements of an .NET array like obj.arr = [f(x) for x in obj.arr] However the assignment back to obj.arr fails. Is it possible to convert a list to a .NET array in IronPython? 回答1: Try this: obj.arr = Array[T]([f(x) for x in obj.arr]) replacing T with type of array elements. Alternatively: obj.arr = tuple([f(x) for x in obj.arr]) 回答2: Arrays have to be typed as far as I know. This works for me: num_list = [n for n in range(10)] from System import Array

Use Python alongside C# in Windows UWP app

烈酒焚心 提交于 2019-12-21 14:08:52
问题 I started writing an application in Python, but I now want to switch to C# and UWP. I know that you cannot write a UWP app in Python, but I am trying to see if I can write some code in Python and access that code from C#. For example, writing a class in Python that C# code can access as well. Is that possible? And if so, can Python access Microsoft's UWP APIs? The main code will not be written in Python; that would be impossible. But can interoperability between C# and Python exist, perhaps

Use Python alongside C# in Windows UWP app

假如想象 提交于 2019-12-21 14:07:10
问题 I started writing an application in Python, but I now want to switch to C# and UWP. I know that you cannot write a UWP app in Python, but I am trying to see if I can write some code in Python and access that code from C#. For example, writing a class in Python that C# code can access as well. Is that possible? And if so, can Python access Microsoft's UWP APIs? The main code will not be written in Python; that would be impossible. But can interoperability between C# and Python exist, perhaps

The definitive method to use NumPy and SciPy from IronPython

人走茶凉 提交于 2019-12-21 12:25:24
问题 There is a way to use NumPy/SciPy in IronPython, using IronClad to execute/communicate with the CPython binaries of the same. A newer project, Python Tools for VS allows for a faster integration with .NET IronPython programs because most of the NumPy/SciPy library functionality has been manually ported into IronPython. Comments on the same page point to this blogpost which links to github projects for the same. As of today (Oct 2012), what is the definitive method to integrate/use these 2

How do I convert from a .NET DateTime to an IronPython datetime?

风格不统一 提交于 2019-12-21 07:25:08
问题 I'm calling an IronPython script and passing it a .NET object that contains a DateTime structure. I'm trying to use IronPython's JSON support to serialize the object as JSON. Everything works great until I encounter the .NET DateTime . How do I convert from the .NET DateTime to the IronPython datetime ? 回答1: Anticipating that people might like to convert between these we actually make it really easy: import datetime from System import DateTime datetime.datetime(DateTime.Now) 回答2: As we know,

IronPython w/ C# - How to Read Values of Python Variables

[亡魂溺海] 提交于 2019-12-21 04:59:26
问题 I have two python files: mainfile.py and subfile.py mainfile.py relies on some types in subfile.py. mainfile.py looks something like this. from subfile import * my_variable = [1,2,3,4,5] def do_something_with_subfile #Do something with things in the subfile. #Return something. I'm attempting to load mainfile.py up in C# and get the value of my_varaible, but I'm having some difficulty finding resources that adequately describe the relationships between the methods I'm calling and I, admittedly

Catching Ironpython Exception in C#

故事扮演 提交于 2019-12-21 04:55:10
问题 I'm embedding IronPython 2.0 in C#. In IronPython, I defined my own exception with: def foobarException(Exception): pass and raise it somewhere with: raise foobarException( "This is the Exception Message" ) Now in C#, I have: try { callIronPython(); } catch (Exception e) { // How can I determine the name (foobarException) of the Exception // that is thrown from IronPython? // With e.Message, I get "This is the Exception Message" } 回答1: When you catch an IronPython exception from C#, you can

“IronPython + .NET” vs “Python + PyQt”. Which one is better for Windows App development?

淺唱寂寞╮ 提交于 2019-12-21 02:04:06
问题 I'm new in using Python. I would like to develop Windows GUI Application using Python. After some research, I found that I have 2 options:- IronPython + .NET Framework Python + PyQt May I know which one is better for Windows Application development? Which option has more features (e.g. database support, etc)? Other than the .NET support, is there any big difference between IronPython and Python? Which one is a better choice for me? Thank you. Patrick.L 回答1: I faced the same issue and have,

NLTK in IronPython from WPF

╄→гoц情女王★ 提交于 2019-12-20 16:21:24
问题 I would like to use NLTK (Natural Language Toolkit) for Python using IronPython and call from an exisiting WPF/c# project. Is it possible to reference NLTK from within WPF in this way. For example to use Named Entity Recognition from NTLK? Any advice or guidance appreciated. 回答1: It definitely is possible, as long as NLTK doesn't use any C extensions. It will be much easier if you use VS2010 though, because of the dynamic keyword. Look at the Microsoft.Scripting.Hosting library from

Simplfying DSL written for a C# app with IronPython

旧城冷巷雨未停 提交于 2019-12-20 12:34:37
问题 Thanks to suggestions from a previous question, I'm busy trying out IronPython, IronRuby and Boo to create a DSL for my C# app. Step one is IronPython, due to the larger user and knowledge base. If I can get something to work well here, I can just stop. Here is my problem: I want my IronPython script to have access to the functions in a class called Lib. Right now I can add the assembly to the IronPython runtime and import the class by executing the statement in the scope I created: // load