Awesome vid, as usual! There's not much out there on the C-API that is this straightforward. I recently wrote my first C-extension with a lot of frustration (I hated C before starting), but I now have an appreciation for it. I got a ~20% speed-up vs the same function implemented in vanilla Python. I'm curious to see how it stacks up against Cython, but I have no idea how to write .pyx
@LoucuraMagic3 жыл бұрын
thank you, that was exactly what i was looking for!
@POP3O23 жыл бұрын
im starting new job as software engineer and they are going to use capi for python 2.7. I find this video so useful. Thanks man! PS. What you like to continue with this topic? ;)
@anthonywritescode3 жыл бұрын
whew 2.7 that's rough! glad this was helpful -- there's some other related things to check out if you don't want to write as much C: kzbin.info/www/bejne/jmbMo6uFart2ftk
@dannymurphy28233 жыл бұрын
Like watching your vids. Even thou I am still to grasping the core concepts of python language itself.
@fernandodiazurbano88152 жыл бұрын
This is a nice video, it was a good watch and to the point.
@anibaldk Жыл бұрын
This is, most of the time, more of a hobby/curiosity than an actual need (which is still great so many thanks). However, it's usually best to check out libraries like numpy/scipy/numba/etc before writing your own C extension.
@anthonywritescode Жыл бұрын
this is terrible advice -- numpy does not help you interface with C libraries and is a behemoth of a dependency to pull in
@anibaldk Жыл бұрын
@@anthonywritescode Perhaps I did not explain myself correctly. I meant to say check it's best to check numpy (or other C based libraries) first than trying to implement the same code. I also don't quite follow the hassle of installing numpy. I never had any trouble with it 🤔 Anyway, thanks for the video. I wanted to learn exactly what you demoed so I'm grateful for it 😊
@tens0r8848 ай бұрын
@@anibaldk I think you either dont quiet understand either what numba does or what the c api is for 😂😂
@DataPastor Жыл бұрын
Great video. A Zig version would also be nice.
@marcello42583 жыл бұрын
same for RUST and GO as mentioned please ;)
@TheNotStated3 жыл бұрын
Thanks for the video! Why we dont have to call Py_DECREF on name variable?
@anthonywritescode3 жыл бұрын
PyArg_ParseTuple I believe gives borrowed references, so unless you're doing something with that object it doesn't need an increment or a decrement
@mastan4193 жыл бұрын
Thanks sir
@nicezombies12 жыл бұрын
Does sys.getrefcount(ANY STRING) by default return 3? Because it didn't change after the code rewrite.
@victordvickie3 жыл бұрын
Is there any advantage of using C++ over C for this and if so can you make a guide?
@anthonywritescode3 жыл бұрын
the python bits have to be `extern "C"` at the least so integrating c++ is kind of tricky. there isn't really much upside other than c++ is a different language than C
@victordvickie3 жыл бұрын
@@anthonywritescode thank you
@angelcaru4 ай бұрын
"there isn't really much of an upside other than the downside"@@anthonywritescode
@j2d513 жыл бұрын
Why we use .c extension to save program
@anthonywritescode3 жыл бұрын
the whole point of this video is to demo a C extension
@Saimon4042 жыл бұрын
How to decompile .so file?
@anthonywritescode2 жыл бұрын
in the general case you cannot -- you can "disassemble" it (to assembly code) -- but getting it back to the original high-level language is impossible
@Saimon4042 жыл бұрын
@@anthonywritescode ok bro,but....
@erjiaxiao65772 жыл бұрын
what does 'pip install .' do?
@anthonywritescode2 жыл бұрын
it installs the source package at `.` (the current directory)
@erjiaxiao65772 жыл бұрын
@@anthonywritescode thanks a lot! it helps!
@jccheloven3 жыл бұрын
Too small font, can't see the code. A pity :-/
@anthonywritescode3 жыл бұрын
the code samples are all up on github.com/anthonywritescode/explains I can't really go any larger on font size (it's already extremely large) -- I'd recommend *not* watching on a phone