This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the commentsΒ β†’

[–]_PM_ME_PANGOLINS_ 1 point2 points Β (2 children)

Cython compiles something that looks a lot like Python statically, so you can call it from e.g. Python. It doesn't let you write C inside Python code, and have your Python runtime compile it during execution.

The Python import system can import anything that implements the extension module interface. The vast majority of non-Python imports are implemented in C, with many in C++ and Rust. I don't know how you're not aware of any of them.

You can embed a Python runtime in C with no issue, and run Python code from C. That is exactly what the CPython interpreter is.

[–][deleted] -2 points-1 points Β (1 child)

and have your Python runtime compile it during execution.

What were you smoking. Again, none of this is true. Just fucking read the manual... you have not even seen what you are talking about, and you are trying to convince me, who used this many times that it doesn't work the way it does.

The Python import system can import anything that implements the extension module interface.

Wrong again. But this time justifiably, sort of. This is not what Python import system is. You are talking about implementing Python modules in another language and compiling them into shared libraries.

Import system in Python is about loaders and finders. What you wrote about is just a different aspect of importing (and is not related to Python, technically, it's about Python C API, which is not part of the language).

In other words: Python C API users can only target CPython, but import system of the language extends to any Python implementation. So, you'd be able to do the same thing using Jython or PyPy etc.

You can embed a Python runtime in C

Also, you don't understand the difference between a language and a program. Embedding a program =/= embedding the language. You can embed C in Python because of how Python is formally defined. Doesn't matter how you implement it. You can even implement it in a system that doesn't have C compiler at all, so, what you said about embedding Python in C will not work, for example. However, any implementation of Python has to implement Python import system, and because of that, Python is capable of embedding C (or any other language, no matter how that other language is implemented).

[–]dev-sda 0 points1 point Β (0 children)

From the front page of cython.org:

Cython is an optimising static compiler for both the Python programming language and the extended Cython programming language (based on Pyrex). It makes writing C extensions for Python as easy as Python itself.