Using Arrays with Python Ctypes

preview_player
Показать описание
In this Video we will discuss how to pass Arrays back and forth between our C and Python programs using the ctypes library.

C File Compilation Command:

Website Link:

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

This really supported me in my code. Ty soooo much!

AngelLilo
Автор

First off, your tutorials are great and appreciate them. Thumbs up!

I am running into an issue where I need to relaunch vscode every time edit and recompile the c function. Otherwise, my python terminal keeps showing the same outputs of the function before I edited + recompiled. Once I close and reopen vscode and run my py code, it shows the correct output reflecting the changes I made to the c function. I am following your example arraySum example exactly line-by-line. Any ideas how to fix this?

bbjohn
Автор

At 12:09 the *arr[10]* gets deleted when goes out of function scope, so that is undefined behaviour in C!

Popart-xhfd
Автор

You can pass numpy arrays and array module arrays too.

undeadpresident
Автор

Hi, thanks for the video, I was just wondering why not do so called inplace "getArray" or is this possible with ctypes?:

#include <stdio.h>
#include <stdlib.h>
 
void getArray(int* arr) {
    for (int i = 0; i <= 10; i++) {
        array[i] = i;
    }
}

The Python will take care of the allocation/deallocation?

Mzkysti