Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I'd like to convert an open source C application to pure python (not to Cython, IronPython etc).

The documentation and presentations of the original creator of the C application has given me a good understanding of the architecture of the application.

Since I want the first version of the python application to be as identical to the C based one, a manual conversion seems to be the best option. I'd appreciate some tips on how to best approach this code conversion (C to Python), based on your experience. (I am just looking for insights on how others have handled a similar task before.)

(Python version 2.7; The C application is the popular database SQLite. Please don't let that or C vs python distract you from the actual question. My C is rusty but good enough for the task, and my Python is above average.)


  • I was planning a manual rewrite. Appreciate advice on how to analyze the C source and header files and things to keep in mind vis-a-vis python.
share|improve this question

2 Answers 2

You probably don't want a line:line conversion.

Python does things differently, so ou want to keep the functionality but probably implement it differently.

The first thing I would do is to make a set of test data, and idealy unit test cases that you can use to confirm what the existing program does in each case and then confirm that your python program does the same.

Another benefit is that it confirms you REALLY understand what the program is supposed to do!

share|improve this answer
It already has a good set of tests, which I do plan to reuse. –  Sam Aug 21 '11 at 7:45

Personally I would re-write from scratch, by hand in Python. Using the desired functionality as the guideline rather than the C code. I'd dig into the C code as needed for functionality that is hidden from the user experience.

Even if an auto-conversion tool exists I would not trust it. I'm just making this example up for the sake of argument..... Lets say there is a set of boolean flags used by the program. The original programmer decides to pack the flags inside of a floating point. He re-interprets the floating point as pointer to an 8 bit char and uses bit twiddling to set the flags. This is going to screw up just about any auto-conversion tool. (the example is unrealistic I know)

share|improve this answer
+1! I too would use the existing program as a living, breathing spec, nothing more. The ported program might end up being slightly different too. –  Job Aug 21 '11 at 3:17
Yes, I had a manual rewrite in mind too. –  Sam Aug 21 '11 at 7:57

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.