Python ctypes Tutorial - Using C/C++ Functions in Python

preview_player
Показать описание
Python as a Programming Language is slower and less efficient in comparison to languages like C and C++. Writing certain parts of your code in C/C++ can significantly improve your performance. The ctypes library creates an interface which allows you to import C/C++ functions and execute them in Python.

C File Compilation Command:

Related Links:
Рекомендации по теме
Комментарии
Автор

You have no idea how much i love your accent😄, please do more share, just free talk is great. I am your fans

yanglijian
Автор

after 2.5 hours of searching, I finally found adequate tutorial.

iancu_de_hunedoara
Автор

Nice quick how-to - very informative, thanks!

MnemonicCarrier
Автор

Video is very informative although the way "Okay" keeps being repeated is a little bit iritating

malborboss
Автор

great this is exactly what I've been looking for and clearly explained

NickSBailey
Автор

The reason why only J was printed and no john before converting into bytes is that when declared in the function as pointer, by default it only points to the 0th value, this is done for efficiency in c, hence, you do not pass entire array right away. You can increment the pointer and get the entire array (string "john") by incrementing pointer in the c function, that would be faster than converting it to bytes first.

Jayveersinh_Raj
Автор

This was explained well. I got to try this. I've been wanting to become proficient in C and speed up the python program I'm working on, but don't have time to go full bore into rewriting the whole thing in C. Maybe I can do it piece by piece and see how it goes.

undeadpresident
Автор

Well done. I have never seen videos like this. Thank you very much

bmbdjvw
Автор

thanks this is what i wanted to learn because i use python libraries that use c libraries

csdnil
Автор

I write DLL's in Pascal. This has been useful to me thank you.

retrojames
Автор

Would be good to see working with pointers and structure

haxidenti
Автор

hiii!! do you know how in python, load a Third part DLL, I´ve just only has documentation of the Methods of the DLL, but I do not Know what is inside. COuld you guide me? please

enrique
Автор

I got this error : OSError: [WinError 193] %1 is not a valid Win32 application
Can anyone help me out?

MatthijsKoelewijn
Автор

function 'display' not found ((((

AlekseyHmelevskoy
Автор

Hi. Thank you for the tutorial. It was great. I am just trying to get a numerical result from function in c to my python code. If the number is big (thousands or millions) it cannot be displayed in the python output, although it works just fine in the c code. Is there any way to make python or ctypes show such numbers.

ankidokolo
Автор

I've copied your code up until 6:57 where I call clibrary's display function, but my thing wont run ;( It just says "AttributeError: function 'display' not found"--what do you think went wrong im sure ive done ive copied you correctly. My third line of code ran just fine

tootyfruity
Автор

can someone please help me with this error, followed the tutorials but still getting this error, Traceback (most recent call last):
File "c:\Users\ragha\OneDrive\Desktop\test\main.py", line 2, in <module>
clibrary =

File "C:\Users\ragha\AppData\Local\Programs\Python\Python312\Lib\ctypes\__init__.py", line 460, in LoadLibrary
return self._dlltype(name)

File "C:\Users\ragha\AppData\Local\Programs\Python\Python312\Lib\ctypes\__init__.py", line 379, in __init__
self._handle = _dlopen(self._name, mode)

OSError: [WinError 193] %1 is not a valid Win32 application

RAGHAVJAIN-umou
Автор

So, `.so` works in Windows and isn't just a *nix thing? I always thought that it had to be `.dll` in/for Windows. (Course, for all I know, he may be running in some flavor of *nix. May have missed that part.)

ScottKFraley
Автор

How to read complete string in python? You are returning it in C but not reading in python!

dapoint
Автор

Ok, ok, ok every five seconds! Pls, do not use the garbage words, it's annoying really!
P.S. The video, by the way, was useful...

maksimluzin