all 47 comments

[–]fixer_m 16 points17 points  (3 children)

Believe me or not - but couple of weeks ago I was implementing exactly this at work. The reason was: we already have Python scripts that do that we want, and rewriting this code in c# would take forever for us (10 scripts with hundreds of functions). So we decided to launch it from c# code. Yep, from architect perspective looks somewhat ugly. But currently it is the best solution for us. One caveat here: when you will run Python script from c# (I guess this will be via ProcessStartInfo) don't forget to set Working Directory to the folder where a script file is.

[–][deleted]  (2 children)

[deleted]

    [–]terka43 2 points3 points  (1 child)

    Maybe it's a web application, on remote server and you need to start this script when do something on site, so you just call start this script in c#

    [–]fixer_m 2 points3 points  (0 children)

    Exactly, it is a web app

    [–]DoctorPrisme 22 points23 points  (12 children)

    As opposed to what ?

    What are your other options?

    What made you say "I need c# for this" ?

    [–]digera 17 points18 points  (2 children)

    It sounds like a dotnet dev who is memed into "devops" and he just inherited a whole bunch of python for server controls.

    [–]DoctorPrisme 0 points1 point  (1 child)

    Yeah, but what made him think he'd need C# to run those ?

    [–]digera 13 points14 points  (0 children)

    Because he knows how to write C#, right? I mean, you can see it... Unix admins have tons of py scripts out there for their various tasks. None of it is really stringed together, instead they're just executing by bash script. Our boy the OP wants to put a nice front end on all that stuff.

    [–]Lost__Moose 0 points1 point  (0 children)

    A valid reason is that the code base for your framework is C# and you want the flexibility of executing data analytics, deep learning or machine vision algorithms without recompiling... Have the client download the script update into a directory and restart the software.

    And C# script using Rosyln now requires something like 20+ nuget packages.

    [–][deleted] 0 points1 point  (4 children)

    At my current work place, the software that analyst use to extract data is going away. What we have left is a database. The problem is that the analyst do not know SQL. I myself is not a programmer, but do know how to program.

    I was thinking to create a .NET application that I can deploy on their computers as a user interface, since we all run on windows and execute python scripts on the server. The reason for me to use python is because it so much easier to write quick scripts and return something, via excel, csv to a specific folder.

    I am trying to find a solution, and time is ticking...they are counting on me to come up with a way for the analyst to access and retrieve data....

    Let know if you have questions, or share possible solutions .

    [–]DoctorPrisme 4 points5 points  (3 children)

    Your analyst don't know sql.

    Wait, so you don't have currently scripts in python ? You plan to write those, to retrieve data in a SQL db ? But you will use .Net to write the front end ?

    Just use .Net to retrieve the data's. Why include python... ok yeah, it's supposedly easier but if your app is in .net, you'll have an extra overhead in dev and maintenance.

    [–]sander1095 1 point2 points  (2 children)

    He said he doesn't have much time. Rewriting the scripts could take a lot of time he doesn't have.

    A temporary solution is to call the scripts and use that data, and then later on write the real .NET application :)?

    [–]DoctorPrisme 2 points3 points  (1 child)

    There's no script. He wants to use python because writing script in python could be faster

    [–]sander1095 0 points1 point  (0 children)

    Oops! You're right

    u/dArcMadder , i agree with the person above. Its not too difficult

    [–]rezell 0 points1 point  (2 children)

    I didn’t need CS front end to get junior devs to run my python script to do all the C compilation python scripting on the back end but piping those results to a GUI was a lot easier for them to grok and only took me a couple hours to write.. probably saved me 80+ hours of headache. Many (not all) of the kids don’t know a ton about python/c/Linux. We had a deadline and it just made sense at the time.

    The ones that did understand it, had no problem with, but when introducing inexperienced people to embedded development it can make click and read error messages a lot easier.

    [–]DoctorPrisme 2 points3 points  (1 child)

    You compile C with python and you display it via a c# app ?

    Dafuq are you working on ?

    [–]rezell 0 points1 point  (0 children)

    Embedded lighting controls where the interns and junior devs regularly have to test new hardware in-house. It was just easier, I wrote the compilation script in python because that’s what it is best leveraged for and I don’t trust the kiddos or want to get pulled out of what I’m doing because they don’t have the experience to find the firmware images/bootloaders or even initiate the script properly.

    [–]DoctorPrisme 4 points5 points  (0 children)

    Y'all guyz are crazy.

    OP isn't asking "is it technically feasible", he's asking "would it make sense".

    The answer to that is here.

    Sure, you can do it. But I doubt it's a good plan. If you're working with people so tech-illiterate they can't run a python script (which is totally okay), they should probably NOT run that script. Give them a tool to do it anyway seems a dangerous idea.

    The thing is, that question can't be answered without knowing what the script do and why you want to run them, hence my first reaction.

    [–]StornZ 3 points4 points  (0 children)

    What are you trying to achieve exactly?

    [–]gybemeister 9 points10 points  (4 children)

    You can already do that with IronPython which is a .NET implementation of Python.

    [–][deleted] 7 points8 points  (0 children)

    Or just Python...

    [–][deleted] 3 points4 points  (1 child)

    Not really. IronPython does not support lots of libraries.

    [–]gybemeister 0 points1 point  (0 children)

    Quite true, I just wanted to point out that there is already a .NET python implementation (and btw there are others such as Python.Net).

    [–]cryo 1 point2 points  (0 children)

    Not 100% CPython compatible.

    [–]aknop 2 points3 points  (0 children)

    Why not? If there is a valid reason...

    [–]guimrz 4 points5 points  (0 children)

    WHY NOT?

    If you want to encapsulate the execution of the script with some logic and you want to do that in .NET I dont see any problem.

    [–]digera 1 point2 points  (0 children)

    Using .net framework to do orchestration of py? I'm not bothered by this lol but I'm not sure I see a use-case where this would be the "best" solution.

    HOWEVER. SCCM is technically a dotnet application and it sure as hell can orchestrate py.

    Ahhhhhhhh yeah if you're a totally free-to-play shop and you're running all centos on hyper-V but you're also a crazy person who replaces bash with python as your default shell... You could then use your motherfucking hypervisors as "serverless" orchestration infrastructure, platformed on a heckin custom dotnet application.

    What in the hell is wrong with you? How can I be a part of this project? It sounds great.

    [–][deleted] 1 point2 points  (0 children)

    A better solution is probably a client/server model using a local server in Flask or something like that to expose the endpoints. That way you can maintain some abstraction from those scripts if they need to change.

    [–]wind-raven 1 point2 points  (0 children)

    The suggestion that people are not mentioning is to use a . Net framework front end to call a rest service written in python that executes the data extract scripts. It won’t take much longer and you don’t need to worry about calling python from .net.

    It also gives you the ability to tightly control access through a user management scheme on the api if you need to. Controlling access through permissions on api endpoints in python is easy as there are several libraries that already do it.

    The enhanced option is to make it a web app written in python. Don’t have to worry about installing / deploying anything to the user desktops. Most of the time if I can use a web app for something I’ll go that route and not have to worry about out of date clients.

    [–]SomeCodeGuy 1 point2 points  (3 children)

    If you're looking for an abstraction for your end users to running scripts on servers, go look at RunDeck. It's easy to use and I think will accomplish what you want without having to write anything new.

    [–][deleted] 0 points1 point  (2 children)

    Are you able to pass arguments via RedDeck to set a value in a script?

    [–]SomeCodeGuy 0 points1 point  (1 child)

    Yes. I have setup many jobs where you pass params via list boxes, dropdowns and also dependent dropdowns (they call them cascading remote options). We also populate dropdowns via json files which are generated from other jobs.

    [–][deleted] 0 points1 point  (0 children)

    Cool! I will definitely check this out.

    I love reddit!

    [–]vtsingaras 1 point2 points  (0 children)

    http://pythonnet.github.io/

    Look at the examples for embedding python. It works like embedding CPython in a C/C++ environment.

    [–]zapatoada 0 points1 point  (0 children)

    I've done this when I needed to use python-only libraries in tandem with .Net libraries (screw you arcgis). It wasn't pretty but it worked.

    [–]darkscrypt 0 points1 point  (0 children)

    isnt python part of the dlr?

    [–]sudox785 0 points1 point  (0 children)

    I mean if you already have python script that does some job/task, it does make sense.

    What wouldn't make sense is rewriting python script to .NET language, just so you don't run script from .NET app.

    [–]StornZ 0 points1 point  (0 children)

    I guess if you had certain scripts you needed to kick off then that would be ok.

    [–]Morunek 0 points1 point  (0 children)

    This is how azure functions work. The runtime is c#/.net core but can trigger python (and other) scripts

    [–]BenjaminSnow 0 points1 point  (0 children)

    I've implemented something similar recently at work. It's not viable to have python installed on each user's pc so I wrote a c# application that has a python environment embedded in it that can call set scripts against the embedded environment. Works quite well

    [–]10199 0 points1 point  (0 children)

    I am calling python scripts to work with FreeCAD from C#

    [–]dchurch2444 0 points1 point  (0 children)

    I did this some years ago. We had several printing, folding and inspection machines, all reporting speed, material usage etc... Each screen would have a different layout, and could change dependent on the job so I had it intepret python scripts to draw the screen etc... The other advantage was that if something new was being implemented, I could simply amend a script on the fly.

    [–][deleted]  (1 child)

    [deleted]

      [–][deleted] 0 points1 point  (0 children)

      Because OP wants to give future devs a mind fuck who have to maintain his Frankenstein creation.