a "hello world" python C extension (intermediate - advanced) anthony explains

  Рет қаралды 11,349

anthonywritescode

anthonywritescode

Күн бұрын

Пікірлер: 33
@chriskorfmann
@chriskorfmann 2 жыл бұрын
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
@LoucuraMagic
@LoucuraMagic 3 жыл бұрын
thank you, that was exactly what i was looking for!
@POP3O2
@POP3O2 3 жыл бұрын
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? ;)
@anthonywritescode
@anthonywritescode 3 жыл бұрын
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
@dannymurphy2823
@dannymurphy2823 3 жыл бұрын
Like watching your vids. Even thou I am still to grasping the core concepts of python language itself.
@fernandodiazurbano8815
@fernandodiazurbano8815 2 жыл бұрын
This is a nice video, it was a good watch and to the point.
@anibaldk
@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
@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
@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 😊
@tens0r884
@tens0r884 8 ай бұрын
@@anibaldk I think you either dont quiet understand either what numba does or what the c api is for 😂😂
@DataPastor
@DataPastor Жыл бұрын
Great video. A Zig version would also be nice.
@marcello4258
@marcello4258 3 жыл бұрын
same for RUST and GO as mentioned please ;)
@TheNotStated
@TheNotStated 3 жыл бұрын
Thanks for the video! Why we dont have to call Py_DECREF on name variable?
@anthonywritescode
@anthonywritescode 3 жыл бұрын
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
@mastan419
@mastan419 3 жыл бұрын
Thanks sir
@nicezombies1
@nicezombies1 2 жыл бұрын
Does sys.getrefcount(ANY STRING) by default return 3? Because it didn't change after the code rewrite.
@victordvickie
@victordvickie 3 жыл бұрын
Is there any advantage of using C++ over C for this and if so can you make a guide?
@anthonywritescode
@anthonywritescode 3 жыл бұрын
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
@victordvickie
@victordvickie 3 жыл бұрын
@@anthonywritescode thank you
@angelcaru
@angelcaru 4 ай бұрын
"there isn't really much of an upside other than the downside"​@@anthonywritescode
@j2d51
@j2d51 3 жыл бұрын
Why we use .c extension to save program
@anthonywritescode
@anthonywritescode 3 жыл бұрын
the whole point of this video is to demo a C extension
@Saimon404
@Saimon404 2 жыл бұрын
How to decompile .so file?
@anthonywritescode
@anthonywritescode 2 жыл бұрын
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
@Saimon404
@Saimon404 2 жыл бұрын
@@anthonywritescode ok bro,but....
@erjiaxiao6577
@erjiaxiao6577 2 жыл бұрын
what does 'pip install .' do?
@anthonywritescode
@anthonywritescode 2 жыл бұрын
it installs the source package at `.` (the current directory)
@erjiaxiao6577
@erjiaxiao6577 2 жыл бұрын
@@anthonywritescode thanks a lot! it helps!
@jccheloven
@jccheloven 3 жыл бұрын
Too small font, can't see the code. A pity :-/
@anthonywritescode
@anthonywritescode 3 жыл бұрын
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
@jccheloven
@jccheloven 3 жыл бұрын
@@anthonywritescode Awesome, thank you!
Python C Extensions
21:59
Tobias Bergkvist
Рет қаралды 8 М.
Now it’s my turn ! 😂🥹 @danilisboom  #tiktok #elsarca
00:20
Elsa Arca
Рет қаралды 12 МЛН
Nurse's Mission: Bringing Joy to Young Lives #shorts
00:17
Fabiosa Stories
Рет қаралды 16 МЛН
Dad gives best memory keeper
01:00
Justin Flom
Рет қаралды 20 МЛН
هذه الحلوى قد تقتلني 😱🍬
00:22
Cool Tool SHORTS Arabic
Рет қаралды 93 МЛН
Compiled Python is FAST
12:57
Doug Mercer
Рет қаралды 109 М.
Python dataclasses will save you HOURS, also featuring attrs
8:50
what are python wheels? (intermediate - advanced) anthony explains #371
22:47
Why is Python so Slow?
10:44
Tech With Tim
Рет қаралды 537 М.
NumPy C-API (Python C extensions)
36:07
Tobias Bergkvist
Рет қаралды 7 М.
Speed Up Your Code With Cython
16:37
NeuralNine
Рет қаралды 116 М.
Now it’s my turn ! 😂🥹 @danilisboom  #tiktok #elsarca
00:20
Elsa Arca
Рет қаралды 12 МЛН