CarlosMZ · 2025-01-22 13:56
Is Python, technically speaking, a C API?
I don't ask this with bad intentions; I love Python. But I was reading the documentation and it seems to me that several Python methods are a kind of wrappers of the functions available in C, though maybe I'm misinterpreting these documents. I know that Python works with a virtual machine à la Java and I find it interesting that Perl uses YACC as back-end.
The idea of extending Python with C has always appealed to me. Do I need Cython to achieve it?
overriding · 2025-01-22 15:52
In a way. For example on Windows, every program that's not a driver has to eventually interact with either the Windows C runtime library (CRT) which handles functions like malloc or printf or the Win32 API which handles functions like HeapAlloc or WriteFile. Actually everything in CRT is implemented using Win32 API functions. I'm hesitant to call Python "just a C API" because as a tradeoff for its interpreted nature, which provides more iterative/prototyping flexibility, it makes it orders of magnitude slower for certain tasks than a compiled equivalent.
CarlosMZ · 2025-01-23 10:18
>>41005
I see, very interesting indeed.
It strikes me very much that, from what I read in the 'glossary' section of the documentation, Python is compiled to bytecode and then interpreted by its own virtual machine which can be disassembled with the 'dis' module. Even in its simplicity, there is a certain complexity that is implicit in the language; beautiful, indeed. I am surprised that Mr. Guido created a mini Java.
By the way, it seems that as of version 13, it is now possible to work without using the Global Interpreter Lock (GIL), but this is an experimental feature.
The Plague · 2025-01-30 08:45
It is indubitably so. The implementation you are using is called CPython and at its origins it was designed very much as a glue language between C libraries. Say you had to gzip decode a file and parse the resulting 100MB CSV, it's a lot easier to do so line by line in Python with all the helper functions than it is to even allocate a buffer in C that will not overrun for that one line that is too long.
DEBUG-CONTENTS · 2025-02-01 19:17
pretty much yeah. hence why projects like Cython and Nuitka exist.
swap · 2025-02-06 09:31
>>41002
Kind of.
Python is a scripting language; something that exists to provide a high-level interface to code written in lower-level languages, and to automate simple tasks where performance concerns are negligible. People will say “import solution” and “all of the good libs are just C wrappers” as if they’re negatives, but really, they’re signs of Python’s success more than anything; that it’s able to become popular without experiencing any significant scope creep.