python and C#
-
I have a script in python. I would like to call it from a winform in C#, is it possible? and how? Thanks
If it works for you from a "command prompt", then
Process.Start()
can handle it. :)Luc Pattyn [My Articles] Nil Volentibus Arduum
-
If it works for you from a "command prompt", then
Process.Start()
can handle it. :)Luc Pattyn [My Articles] Nil Volentibus Arduum
-
If you know how to do it from a "command prompt", then Process.Start() can handle it. :)
Luc Pattyn [My Articles] Nil Volentibus Arduum
-
If you know how to do it from a "command prompt", then Process.Start() can handle it. :)
Luc Pattyn [My Articles] Nil Volentibus Arduum
-
I can not. :)
Luc Pattyn [My Articles] Nil Volentibus Arduum
-
I think you can. Because from Csharp we can call another dll's functions by importing them with DllImport. However your python script should be a dll that registered to the system once ;)
-
I have a script in python. I would like to call it from a winform in C#, is it possible? and how? Thanks
Yes it is. You need to install Iron Python[^. Then you gain access to your Python functions directly from .NET.
*pre-emptive celebratory nipple tassle jiggle* - Sean Ewington
"Mind bleach! Send me mind bleach!" - Nagy Vilmos
My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility
-
I have a script in python. I would like to call it from a winform in C#, is it possible? and how? Thanks
You can use IronPython[^] in a C# application. A simple implementation of loading a python file using IronPython looks something like this:-
Console.WriteLine("Loading discountprice.py");
ScriptRuntime py = Python.CreateRuntime();
dynamic random = py.UseFile(@"D:\Documents\Python Scripts\discountprice.py");
Console.WriteLine("discountprice.py loaded.");that snippet loads a basic python file called discountprice.py in my python scripts folder. To implement this you need to download IronPython and reference
Microsoft.Scripting.Hosting
and alsoIronPython.Hosting
. Hope this helpsWhen I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
-
You can use IronPython[^] in a C# application. A simple implementation of loading a python file using IronPython looks something like this:-
Console.WriteLine("Loading discountprice.py");
ScriptRuntime py = Python.CreateRuntime();
dynamic random = py.UseFile(@"D:\Documents\Python Scripts\discountprice.py");
Console.WriteLine("discountprice.py loaded.");that snippet loads a basic python file called discountprice.py in my python scripts folder. To implement this you need to download IronPython and reference
Microsoft.Scripting.Hosting
and alsoIronPython.Hosting
. Hope this helpsWhen I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
Thanks it helps. (tried it with a simple script) my question now is: I have a python script that import module IntelHex. when executing the script itself it works properly. when calling it frm my C# application, I got an exception "No module named intelHex" Do you have a clue how can I solve this? Thanks,
-
do you know how can I turn the python script into a dll. Or should I forward the question to the phyton forum?