ironpython

Looping over a Python / IronPython Object Methods

﹥>﹥吖頭↗ 提交于 2019-12-01 19:38:49
What is the proper way to loop over a Python object's methods and call them? Given the object: class SomeTest(): def something1(self): print "something 1" def something2(self): print "something 2" You can use the inspect module to get class (or instance) members: >>> class C(object): ... a = 'blah' ... def b(self): ... pass ... ... >>> c = C() >>> inspect.getmembers(c, inspect.ismethod) [('b', <bound method C.b of <__main__.C object at 0x100498250>>)] getmembers() returns a list of tuples, where each tuple is (name, member). The second argument to getmembers() is the predicate, which filters

Is there a good IDE for building GUI apps with Python [closed]

非 Y 不嫁゛ 提交于 2019-12-01 18:59:20
I am a beginner programmer and have learned most of what I know thus far from using delphi for the past couple of months. A month or so back I decided to give python a try as I was told it may be easier to learn and I really like the language. I guess I just seem to pick things up easier using it. The only problem is that I can't seem to find a good IDE for it that works in the way that Delphi does. I want to create desktop apps with nice GUIs so it would be nice to have something similar to Delphi/Visual studio to work with. I have searched around and could find anything. Was wondering if

Import Python Module through C# .NET using IronPython

对着背影说爱祢 提交于 2019-12-01 18:07:23
问题 I am trying to run a Python class through C# .NET using IronPython, a couple of the Modules imported by the Python class are: import collections import nltk.classify.util In order to import these when running IronPython, I am using the GetSearchPath collection of the ScriptEngine to add the path to the location of the Python library, as such: ICollection<string> paths = pyEngine.GetSearchPaths(); string dir = @"C:\Python27\Lib\"; paths.Add(dir); string dir2 = @"C:\Python27\Lib\site-packages

Import Python Module through C# .NET using IronPython

让人想犯罪 __ 提交于 2019-12-01 17:51:34
I am trying to run a Python class through C# .NET using IronPython, a couple of the Modules imported by the Python class are: import collections import nltk.classify.util In order to import these when running IronPython, I am using the GetSearchPath collection of the ScriptEngine to add the path to the location of the Python library, as such: ICollection<string> paths = pyEngine.GetSearchPaths(); string dir = @"C:\Python27\Lib\"; paths.Add(dir); string dir2 = @"C:\Python27\Lib\site-packages\nltk\classify\"; paths.Add(dir2); pyEngine.SetSearchPaths(paths); This seems to run fine for the

C# dynamic compilation and “Microsoft.CSharp.dll” error

柔情痞子 提交于 2019-12-01 17:49:06
I'm doing the example that can be found here . So I'm trying to run IronPython in a C# script: Python: def hello(name): print "Hello " + name + "! Welcome to IronPython!" return def add(x, y): print "%i + %i = %i" % (x, y, (x + y)) return def multiply(x, y): print "%i * %i = %i" % (x, y, (x * y)) return C#: using IronPython.Hosting; using IronPython.Runtime; using Microsoft.Scripting.Hosting; using System; namespace IntroIronPython { class IronPythonMain { static void Main(string[] args) { // Create a new ScriptRuntime for IronPython Console.WriteLine("Loading IronPython Runtime...");

C# dynamic compilation and “Microsoft.CSharp.dll” error

拈花ヽ惹草 提交于 2019-12-01 16:58:10
问题 I'm doing the example that can be found here. So I'm trying to run IronPython in a C# script: Python: def hello(name): print "Hello " + name + "! Welcome to IronPython!" return def add(x, y): print "%i + %i = %i" % (x, y, (x + y)) return def multiply(x, y): print "%i * %i = %i" % (x, y, (x * y)) return C#: using IronPython.Hosting; using IronPython.Runtime; using Microsoft.Scripting.Hosting; using System; namespace IntroIronPython { class IronPythonMain { static void Main(string[] args) { //

How do I create a C# event handler that can be handled in IronPython?

谁都会走 提交于 2019-12-01 09:36:13
How do I create a C# event handler that can be handled in IronPython? Note that I am using IronPython 2.0.1. I am able to handle events from system classes with no problems (eg Window.KeyDown) but when I try to define my own C# event an exception is raised when I attempt to hook it from IronPython. The exception thrown is ArgumentTypeException and it has the message "cannot add to private event". The message seems odd considering the event I am trying to hook is public. My C# class looks like this: class Foo { ... public event EventHandler Bar; } My IronPython setup code looks like this:

IronPython - Load script from string in C# 4.0 application

▼魔方 西西 提交于 2019-12-01 08:50:20
问题 I have the following code (just a test): var engine = Python.CreateEngine(); var runtime = engine.Runtime; try { dynamic test = runtime.UseFile(@"d:\test.py"); test.SetVariable("y", 4); test.SetVariable("client", UISession.ControllerClient); test.Simple(); } catch (Exception ex) { var eo = engine.GetService<ExceptionOperations>(); Console.WriteLine(eo.FormatException(ex)); } But I would like to load the script from a string instead. 回答1: You can use engine.CreateScriptSourceFromString to load

.net framework with scrapy python [closed]

孤街醉人 提交于 2019-12-01 08:49:50
Is it possible to use .NET framework with the Python scrapy framework to scrape data from different sites? I am working on my final year project in which I want to use C# as front end language and Python for scraping the data. Hemache I don't think it is possible, because Scrapy uses twisted networking engine which can not run on IronPython Alternatively, you may start your spider/crawler through command line using C# and then interact with it using JSON API Take a look at ScrapySharp , also described on this blog , which is the C# version of python's Scrapy. 来源: https://stackoverflow.com

Python for .NET: Using same .NET assembly in multiple versions

一笑奈何 提交于 2019-12-01 08:37:09
My problem: I have an assembly in 2 versions and want to use them at the same time in my Python project. The .NET libs are installed in GAC (MSIL), having the same public token: lib.dll (1.0.0.0) lib.dll (2.0.0.0) In Python I want something like that: import clr clr.AddReference("lib, Version=1.0.0.0, ...") from lib import Class myClass1 = Class() myClass1.Operation() *magic* clr.AddReference("lib, Version=2.0.0.0, ...") from lib import class myClass2 = Class() myClass2.Operation() myClass2.OperationFromVersion2() *other stuff* # both objects should be accessibly myClass1.Operation() myClass2