Python to C# Converter

So I want to transpose my AI Guessing Game from Python to C#. But so far, all the converters either didn’t work like pythoncsharp.com, or had to be downloaded.

If there is no such thing as a Python to C# Converter, how about Python to C or Python to C++?

Also I don’t want it to be a PEP, a Python extension, or a “need to be downloaded” file. I want it to be online, download-free, and one that actually works.

Well it has been 2 days since I posted this post, and no one has the answer.

So I guess there is no download-free online Python to C# Converter available.

Hello Jayden Liu … depends what OS you are using … in Linux there is
this converter with name “cython” - it is a converter from C to Python. But it is case-sensitive. I guess it works only with Python 2.7 and it can be dangerous to try it with Python 3.9 (you need always to back up your out-worked python-files before to convert some of them). I don’t know if “cython” is maintained yet ?!

The main Cython page at https://cython.org/ correctly states that it
converts a Python-like language to C/C++. Maybe that’s what you
meant, but you stated the opposite. And Cython’s documentation
includes tutorials for using it on Windows too, so probably not
accurate to claim it’s Linux-only (though I’ve only used it on Linux
personally, so I can’t vouch for how well it works on Windows).

It’s also not accurate to say it “only works with Python 2.7”
insofar as you can use its current official releases to create C
extensions for Python3-based projects, you just need to use Cython
language_level 2 (a Python 2.x style syntax) for the code you want
to convert to C. Further, Cython 3.x (alpha releases available for
the past 1.5 years and improving) uses a Python3-like syntax with a
language_level of 3.

As for whether Cython is maintained, it’s been under active
development for over a decade and is widely used by many popular
Python libraries to generate optimized C extensions.

I’m really not sure what you meant by “but it is case-sensitive.”
Isn’t all of Python case-sensitive too?

However, the original question was about converting Python to C#,
not C/C++. There is a Python interpreter implemented in C# called
IronPython, not exactly a converter from Python to C# but it claims
to include a lot of .NET tie-ins, if that’s what you’re looking for:

https://ironpython.net/

Hope that helps.

2 Likes

Thank you for your concrete answer to me.
I completely have overseen this - somehow I did wrong queries in browser
about cython as package longer ago - and gave up too early.
My answer above is then for the cat …

Is cython a download free software?

Cython is Open-Source and therefore free. You can read anything there at
their homepage.

I meant “do you need to download the software or is it online?”

Cython is software you install and run to turn a Python-like
language into optimized C source code (note that its language is not
quite Python by the way, it just has a similar syntax). Cython is
not software-as-a-service you interact with over the Internet
through a Web browser or anything like that, if that’s what you’re
asking.

It exists primarily in order to provide a way for Python-based
software to be distributed with optimized extensions which can be
compiled automatically by native C compilers on target systems at
installation, for people who want to write those extensions in a
high-level language more like Python.

Python is very rarely run in the browser. The same goes for C#, C and C++. Python development might happen in a web browser with something like Jupyter, but almost universally the Python interpreter will still be running as a native executable, either on a server (such as Google Colab’s server), or on your own PC.

Python-related development tools are often written in Python, and even when they’re not, they’ll generally be designed to run “where Python runs”, i.e. on a desktop computer, or possibly a server. Not in a browser.

I just wanted to point out that if there is a tool that does what you want it to do (and that works), it is fairly likely that it will be designed to run locally on your computer, not on somebody’s web server, and not in your web browser.

After all, you presumably downloaded and installed Python as well if you’re programming in Python.

In short yes - Python runs only there, where Python is installed. No matter if Desktop or if Server. This is too - in case when there is web-development with Django.

Hello Jayden,

I’m confused. Doesn’t PythonCSharp do exactly what you are asking for?

It is free, it doesn’t need to be downloaded, it runs in your browser.

https://pythoncsharp.com/

I said it doesn’t work

Also don’t say my real name. I want to be safe online.

What makes you say it doesn’t work? It worked when I tried it.

When you transposed MY Python code into C# code with pythoncsharp.com?

Hello world!

I personally use OpenAI’s GPT-3 model to convert Python code to C#, though it’s not limited to! You can pretty much convert any programming language code to any programming language code and more, but that’s off-topic…

Is it download-free? Yes
Is it free? No. However, they let you have 18$ credit to use as a free trail, which can last for a whole month of use, however, I think it’s only available for the first 3 moths and then it’s gone.
Does it work ? Kinda…
It might not work (at this time) if your code is too large, it performs well with built-in libraries, however I was able to make it generate code with non built-in libraries. Keep in mind that it’s ai-generated, so you might be required to do some adjustments.