I'm Not Technical, but.....

Python in C# web app


I'm not technical, but...For a long time now, I have wanted to use Python is some way, just to get experience built up. Was it easy? Hell No!!! It took a number of hours to get my head around the setup. It's straight forward, however, there are some nuances that need to be ironed out. Firstly, you have to import the CSnakes nuget package, and then reference that within your app. I started with a console app, as not to over complicate the process. The problem I had was that the latest version of CSnakes is a little different and the errors that popped up, I couldn't quite work out. I asked trusty Chat-GPT, but that went down a rabbit hole of failure or including workarounds that I didn't want to explore. Looked at some videos and ended up going back to an earlier version of CSnakes. This got it working, and I think after tinkering about I did actually get the newer version working, but there was a warning and I don't really like warnings. Also, I believe there was some issue with finding my Python script files.

Anyway, back to a clean build and a successful running Python script. Now was the tiem to implement it in my Blazor web application, which was ultimately the cherry on the pie. Now it all makes sense, but having it working in my console app, I kind of thought it would just work in the razor page that I had waiting for it. Unfortunately, after Chat-GPT was just spinning me around in circles, I had to make a decision. Do I just give up, or stick with my usual habit of keep pushing until the target has been reached? You guessed it, the latter.

So I ditched Chat-GPT and jumped over to Google Gemini. While I prefer Chat-GPT for the ego-boost, if it doesn't help, you have to sacrifice for the good of the land. Gemini started down the same path, however, I was prepped with experience now, and forced it down a better route, to which it came up with the solution for me to try. What I had to do was create a class that would act as a broker service to connect me to Python files, and.... it just worked. As the Python scripts were all in the root, I had a little tinkering to do, but safely deposited them into their own crib.

Now I was on a roll, and I wanted to create functionality that would get data from an API call, format it into a HTML response and return that back to Blazor and add it to the web page. There you have it as a screenshot above, all nicely working. A Python course is my next venture, and who knows what I will be able to create from this point onwards. Watch this space.

An unhandled error has occurred. Reload 🗙