Greetings;
Please, is there a 'python tool' of sorts (ide or whatever) that will convert Python code to 'C' code .
Thanks!

Recommended Answers

All 5 Replies

The closest thing would probably be Shed Skin that translates Python code to rather ugly C++ code. See:
http://en.wikipedia.org/wiki/Shed_Skin

A number of students have attempted a Python to C translator but failed because of the dynamic typing.

You need to do it manually , also it is not 100% compatible with C.

Python is a modern language that has borrowed advanced programming concepts from a number of other languages like C++, Java, Lisp and Haskell. It would be very hard to express these in C.

> that will convert Python code to 'C' code .
Why?
Performance reasons?

As already stated, replicating a lot of the "free" functionality using your own C code is going to take work.

Also, python (in common with many modern interpreted languages) is bytecode compiled before it is run. If your program runs for any length of time, then this 'hit' at the start is negligible. The "interpreter == slow" paradigm doesn't hold so much nowadays.

Besides, if you've made dumb (ie expensive) performance decisions in your python code, then it would make sense to address these before trying to translate (somewhat literally) into C (where it will still suck).

If you're still worried about performance, then consider this.
http://www.python.org/doc/2.2.3/ext/ext.html
That is, focus on isolating the bit which really matters and write that in C, then wrap it up so you can call it from python.

There is a large body of literature available for embedding Python code in a C program. The official reference for embedding in C can be found at http://www.python.org/doc/current/c-api/. This may be of interest to you if you are looking to use Python code from a C program.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.