In Python's tutorial one can read that Python's original implementation is in C;

On the other hand, the Python implementation, written in C, (...)

I'm very curious why was Python written in C and not C++?

I'd like to know the reasoning behind this decision and the answer should be supported by historical references (and not opinion based).

  • 10
    I don`t know why, but I suspect something close to this : thread.gmane.org/gmane.comp.version-control.git/57643/… :)
    – Matthieu
    Commented Nov 23, 2010 at 21:45
  • 13
    @Larry Coleman: Never seen Linus rants? You must be avoiding "the internets"... >_> Commented Nov 23, 2010 at 22:02
  • 18
    @Larry I did see this rant and lost almost all respect for Linus after reading it. Shame on him. Commented Nov 23, 2010 at 22:04
  • 5
    Well, this is a response to Linus' rant, what about this : warp.povusers.org/OpenLetters/ResponseToTorvalds.html
    – avi
    Commented Jun 6, 2013 at 18:34
  • 6
    I fail to see the point of asking "why is (popular program) written in (language X) and not (language Y)?". Or rather, the same question can be reversed: why Y and not X?
    – Andres F.
    Commented Jun 12, 2013 at 18:49

3 Answers 3


From everything I've seen, it's a combination of practical and historical reasons. The (mostly) historical reason is that CPython 1.0 was released in 1989. At that time, C was just recently standardized. C++ was almost unknown and decidedly non-portable, because almost nobody had a C++ compiler.

Although C++ is much more widespread and easily available today, it would still take a fair amount of work to rewrite CPython into the subset of C that's compatible with C++. By itself, that work would provide little or no real benefit.

It's a bit like Joel's blog post about starting over and doing a complete rewrite being the worst mistake a software company can make. I'd counter that by pointing to Microsoft's conversion from the Windows 3.0 core to the Windows NT core, and Apple's conversion from MacOS 9 to Mac OS/X. Neither one killed the company -- but both were definitely large, expensive, long-term projects. Both also point to something that's crucial to success: maintaining both code bases for long enough that (most) users can switch to the new code base at their leisure, based on (at least perceived) benefits.

For a development team the size of Python's, however, that kind of change is much more difficult. Even the change from Python 2 to 3 has taken quite a bit of work, and required a similar overlap. At least in that case, however, there are direct benefits to the changes, which rewriting into C++ (by itself) wouldn't (at least immediately) provide.

Linus Torvalds's rant against C++ was brought up, so I'll mention that as well. Nothing I've seen from Guido indicates that he has that sort of strong, negative feelings toward C++. About the worst I've seen him say is that teaching C++ is often a disaster -- but he immediately went on to say that this is largely because the teachers didn't/don't know C++.

I also think that while it's possible to convert a lot of C code to C++ with relative ease, that getting much real advantage from C++ requires not only quite a bit more rewriting than that, but also requires substantial re-education of most developers involved. Most well-written C++ is substantially different from well-written C to do the same things. It's not just a matter of changing malloc to new and printf to cout, by any stretch of the imagination.

  • 1
    +1 specifically for mentioning the c which can be ported to c++ with relative ease is probably not worth doing. I knew this already for a long time but the answer really strengthened point of view plus added several dimensions to look at it.
    – fkl
    Commented Dec 5, 2013 at 6:44
  • 1
    "Apple's conversion from MacOS 9 to Mac OS/X" note that OS/X is not a rewrite from scratch: it was rather a switch from MacOS9 to NeXTStep, improved and rebranded for Apple
    – Jivan
    Commented Dec 29, 2014 at 5:43
  • So is Python essentially a software written in C (not the interpreters itself)? Is that what is meant by "Python implemented in C"? I'm trying to understand the difference in "Java being a derivative or C" and "Python being written in C". I understand that the certain JVMs are written in C/C++ Commented Jul 9, 2016 at 8:58

I think the reason why it was originally written in ANSI C89 is quite simply because back then, C++ was just not a workable choice what with incompatibilities between different compilers and such. I mean, it took until, what was it, 2005, to come up with an ABI specification that would allow code compiled with one compiler to call code compiled with a different compiler?

The more interesting question is why it is still written in C89.

And there is a surprising answer: because people actually use Python on platforms for which no C++ and no C99 compiler exists! When the Forth-inspired threaded-code interpreter optimizations were merged, there was a huge discussion about it, because the code (necessarily) used computed goto which is not a part of C89. There were apparently real fears that this feature might not be available on some of the platforms that Python is currently used on.

The same thing happened with Unladen Swallow, wich uses LLVM, which is written in C++. It was made very clear that a requirement for merging Unladen Swallow into CPython would be that you can compile it without the JIT compiler, since there are platforms people run Python on, for which no C++ compiler exists.

Of course, nowadays, CPython is no longer the only Python implementation. There is PyPy, which is written in RPython (a statically typed subset of Python), Jython in Java, IronPython in C#, Pynie in NQP and PIR and so on.

  • 3
    I'm half tempted to upvote this, but I know of no such platform where a C++ compiler does not exist (Particularly given that Comeau C++ compiles to C) Commented Feb 14, 2011 at 23:58
  • 1
    +1 for mentioning the ABI
    – jk.
    Commented Jun 13, 2013 at 11:12
  • 3
    @Abdul: No, Python is not a software at all. It is a specification. There are multiple implementations of that specification, written in multiple languages. IronPython is written in C♯, Jython in Java, PyPy in RPython, Pynie in NQP, PIR, and Perl6, Pyston in C++, CPython in C. The statement "Python is written in C" doesn't make sense. Python is not a software. It is a specification. It is written in English, not in any programming language. "Java is a derivative of C" is mainly wrong. Java is inspired by Objective-C, but it gets rid of most of the C parts and takes mostly the Smalltalk parts. Commented Jul 9, 2016 at 14:28
  • 4
    @MilesRout: There are multiple cases where the specification deviates from CPython. For example: the Python specification does not guarantee deterministic finalization, but CPython does, at least for non-circular references. But even though CPython guarantees deterministic finalization for non-circular references, writing code which relies on that fact is broken, since it is not part of the spec. (I can't find the quote right now, but GvR has explicitly said that deterministic finalization and reference counting are private internal implementation details of CPython.) Commented Oct 18, 2017 at 11:58
  • 4
    Similarly, CPython guarantees that two Python threads cannot execute in parallel, but that, too, is a private internal implementation detail of CPython and not guaranteed by the language spec. If what you say were true, there couldn't possibly be any other implementations, since any alternative implementation must necessarily behave identical to CPython, and thus must necessarily be identical. (Modulo refactorings that don't change observable behavior.) Commented Oct 18, 2017 at 12:02

A better question might be: "Why isn't Python written in Python?"

More to the point, once enough primitives for Python classes and objects are written in C, those can be used for writing the rest of the interpreter, so you wouldn't gain anything by using C++ instead.

  • 1
    If you follow the first link in my answer, you will see a reference to an implementation of Python in Python. That is not production ready yet. That is funded by the EU. codespeak.net/pypy/dist/pypy/doc is the link if it is difficult to find out from my answer.
    – vpit3833
    Commented Nov 23, 2010 at 22:02
  • 2
    This is actually a pretty deep answer. Not that Guido's Python is literally written in Python but that the low level structures in C are used to write higher-level ones.
    – Jeremy
    Commented Nov 24, 2010 at 1:43
  • 1
    I think you miss the point as there's quite a difference (for people working on the interpreter itself) what language the interpreter is written in. The language influences how these primitives look like and how they interact with each other. For instance now, in C implementation of Python, one has to remember to increment and decrement reference counts manually whereas it might be possible to use smart pointers in C++ for this. Commented Jul 28, 2014 at 14:06
  • Now that PyPy is available and interestingly outperforms CPython sometimes, it would have been such a great idea I think. Commented Jul 20, 2018 at 11:41

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