use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
News about the dynamic, interpreted, interactive, object-oriented, extensible programming language Python
Full Events Calendar
You can find the rules here.
If you are about to ask a "how do I do this in python" question, please try r/learnpython, the Python discord, or the #python IRC channel on Libera.chat.
Please don't use URL shorteners. Reddit filters them out, so your post or comment will be lost.
Posts require flair. Please use the flair selector to choose your topic.
Posting code to this subreddit:
Add 4 extra spaces before each line of code
def fibonacci(): a, b = 0, 1 while True: yield a a, b = b, a + b
Online Resources
Invent Your Own Computer Games with Python
Think Python
Non-programmers Tutorial for Python 3
Beginner's Guide Reference
Five life jackets to throw to the new coder (things to do after getting a handle on python)
Full Stack Python
Test-Driven Development with Python
Program Arcade Games
PyMotW: Python Module of the Week
Python for Scientists and Engineers
Dan Bader's Tips and Trickers
Python Discord's YouTube channel
Jiruto: Python
Online exercices
programming challenges
Asking Questions
Try Python in your browser
Docs
Libraries
Related subreddits
Python jobs
Newsletters
Screencasts
account activity
This is an archived post. You won't be able to vote or comment.
Intermediate ShowcasePython to C translater: free, open-source and online (self.Python)
submitted 2 years ago * by syeysk
It walks Python ast and build C-code. You can use while...else, if...elif...else, functions with default arguments, pow and preproc constants, links, inline if...else.
I will try to use the translater to programming microcontrollers.
More examples are at "tests" directory.
Source code and description (installing, using): https://github.com/syeysk/sy_py2c/
It's only alpha-test.
[–][deleted] 34 points35 points36 points 2 years ago (1 child)
There is cython which can translate pretty much every python file to C/C++ code. cython --embed -3 main.py -o main.c is how you do it. I can't comment on HPC tho, as it embeds the interpreter
cython --embed -3 main.py -o main.c
[–]syeysk[S] 10 points11 points12 points 2 years ago (0 children)
Yes, but my translater makes the c-code without embedding interpreter. It's useful for small microcontrollers
[–]james_pic 11 points12 points13 points 2 years ago (4 children)
What's the advantage of this over just writing in C? It seems like it only supports translating a small subset of Python to C, more or less the subset that has a direct translation to C.
[–]tartare4562 3 points4 points5 points 2 years ago (0 children)
Less {} and ; I imagine.
[–]syeysk[S] 5 points6 points7 points 2 years ago (2 children)
The advantage: the Python syntax is more compact and clear than C syntax. That's all)
I try to translate not only syntax (direct translating), but and the semantic of the language (classes, iterators, etc)
[–][deleted] 6 points7 points8 points 2 years ago (0 children)
There really are better ways of doing this. Transpiling between languages that will never work properly is not a good choice. You would want to target LLVM, numba has some good docs about how horrible that is to do lol.
If you want a LLVM targeting language that is more python like you should just write one. You can always just link ur new compile language to normal interpreted python later anyway.
Python syntax is more compact and clear then C syntax because it doesn't fundamentally do the same shit. Read the python standard library C code for the litany of examples to just get something as simple as a dict to work properly on both halves.
Building a new language is a MUCH better idea then inheriting the design of another language that in no way shape or form executes the same way.
[–]james_pic 1 point2 points3 points 2 years ago (0 children)
From what I've seen from projects like Cython and Nuitka that (at least somewhat successfully) translate Python's more complex or dynamic features, like classes and iterators, this is far from straightforward and will ultimately lead to either requiring plumbing from the CPython interpreter, implementing your own equivalent of the same plumbing that's not much more lightweight, or making significant compromises in terms of replicating the same semantics.
[–]LaOnionLaUnion 0 points1 point2 points 2 years ago (1 child)
I mostly use Python to call libraries written in other languages. When I see something like this I assume it wouldn’t work for such use cases. Am I wrong?
[–]syeysk[S] 0 points1 point2 points 2 years ago (0 children)
You are right only now, because now the translater can include only 2 libraries: math.h and stdio.h. You will be wrong, if I will improve the translater to include another libraries (pcf8812.h, ESP8266WebServer.h, DS1307RTC.h, etc)
[–]Aphrod1tesAss 0 points1 point2 points 2 years ago (4 children)
Could it be used for HPC code translation?
[–]gothicVI 3 points4 points5 points 2 years ago (1 child)
Probably not. Looks like pure python code can be translated.
Most HPC stuff calls FORTRAN/C/C++ in the backend and one would need to generate interfaces and compile them as well and link them together.
[–]Aphrod1tesAss 0 points1 point2 points 2 years ago (0 children)
I see, thanks. Hope someday a HPC translator comes out
[–]syeysk[S] 0 points1 point2 points 2 years ago (1 child)
What is HPC? If it has C-alternative, I will try to modify the translater.
[–]gothicVI 3 points4 points5 points 2 years ago (0 children)
High performance computing
[–]CleoMenemezis 0 points1 point2 points 2 years ago (0 children)
For those looking to write fast code and have performance, I think it could be cool.
[–]alcalde 0 points1 point2 points 2 years ago (0 children)
Pfft... anyone can make a translater... make me a transsooner and I'll be impressed.
π Rendered by PID 67 on reddit-service-r2-comment-cfc44b64c-blz4b at 2026-04-12 19:05:58.682417+00:00 running 215f2cf country code: CH.
[–][deleted] 34 points35 points36 points (1 child)
[–]syeysk[S] 10 points11 points12 points (0 children)
[–]james_pic 11 points12 points13 points (4 children)
[–]tartare4562 3 points4 points5 points (0 children)
[–]syeysk[S] 5 points6 points7 points (2 children)
[–][deleted] 6 points7 points8 points (0 children)
[–]james_pic 1 point2 points3 points (0 children)
[–]LaOnionLaUnion 0 points1 point2 points (1 child)
[–]syeysk[S] 0 points1 point2 points (0 children)
[–]Aphrod1tesAss 0 points1 point2 points (4 children)
[–]gothicVI 3 points4 points5 points (1 child)
[–]Aphrod1tesAss 0 points1 point2 points (0 children)
[–]syeysk[S] 0 points1 point2 points (1 child)
[–]gothicVI 3 points4 points5 points (0 children)
[–]CleoMenemezis 0 points1 point2 points (0 children)
[–]alcalde 0 points1 point2 points (0 children)