Seite 1 von 1
ctypes: Multidimensionaler Array
Verfasst: Sonntag 21. Dezember 2008, 19:10
von name
Ich habe folgendes C-struct:
Code: Alles auswählen
struct Board
{
short filled;
char board[6][6];
char colour;
};
Nun wäre meine Frage wie ich dieses mit ctypes.Structure wrappe. Hoffe ihr könnt mir dabei helfen.
Verfasst: Sonntag 21. Dezember 2008, 19:18
von sma
Dies ist geraten nach den Beispielen aus der
Dokumentation:
Code: Alles auswählen
from ctypes import *
class Board(Structure):
_fields_ = [
("filled", c_short),
("board", c_char * 6 * 6),
("colour", c_char)]
Stefan
Verfasst: Sonntag 21. Dezember 2008, 19:19
von Trundle
Code: Alles auswählen
import ctypes
class Board(ctypes.Structure):
_fields_ = [
('filled', ctypes.c_short),
('board', (ctypes.c_char * 6) * 6),
('colour', ctypes.c_char),
]
Edit: zu langsam.
Verfasst: Sonntag 21. Dezember 2008, 19:20
von name
Oha. das ging ja schnell. Dankeschön!
Blöd ist nur, das ich da meine Zahlen explizit mit chr in chars konvertieren muss, wo mir das meine C-Helper doch implizit gemacht haben
EDIT: s/c_char/c_byte/ löst auch das
