ctypes

Python, ctypes and mmap

I am wondering if it is possible for the ctypes package to interface with mmap. Currently, my module allocates a buffer (with create_string_buffer) and then passes that using byref to my libraries mylib.read function. This, as the name suggests, reads data into the buffer. I then call file.write(buf.raw) to write the data to disk. My be...

Python: quickly loading 7 GB of text files into unicode strings

I have a large directory of text files--approximately 7 GB. I need to load them quickly into Python unicode strings in iPython. I have 15 GB of memory total. (I'm using EC2, so I can buy more memory if absolutely necessary.) Simply reading the files will be too slow for my purposes. I have tried copying the files to a ramdisk and th...

Use of ctypes module

Hi; I need to program VIX API of VMware. It´s a dll wrote with C functions... I want program in python calling this functions using ctypes and I don´t understand the documentation of ctypes in python web page... Can someone give some samples with how to do this???? Thanks, ...

Python ctypes - Accessing data string in Structure .value fails

I am able to get a Structure populated as a result of a dll-function (as it seems looking into it using x=buffer(MyData) and then repr(str(buffer(x))) ) But an error is raised if I try to access the elements of the Structure using .value I have a VarDefs.h that requires a struct like this: typedef struct { char Var1[8+1]; char...

Strings in Python 3

Hi: I am programing VIX API from python 2.5, but now I want to port the code to python 3.2 This funtion opens the virtual machine: self.jobHandle = self.VixLib.vix.VixVM_Open(self.hostHandle, "C:\\MyVirtualMachine.vmx", None, None)e...

Python ctypes, C++ object destruction

Consider the following python ctypes - c++ binding: // C++ class A { public: void someFunc(); }; A* A_new() { return new A(); } void A_someFunc(A* obj) { obj->someFunc(); } void A_destruct(A* obj) { delete obj; } # python from ctypes import cdll libA = cdll.LoadLibrary(some_path) class A: def __init__(self): self.obj...

Occasional ctypes error importing numpy from mod_wsgi django app

Here's the setup: Django (1.2) app on mod_wsgi that imports ctypes Python 2.6.5 Apache 2.2.3 SELinux disabled RedHat EL 5 64bit some of the file system is mounted over nfs Occasionally, when I restart apache I get an import error when it's trying to import ctypes. Every incoming request fails with a 500 error. If I restart apache usu...

Problem with using Win32 IPHelper API in python

I'm attempting to create python module for getting network parameters. I'm using ctypes and has some problems. Function __getInterfaces_win2k() works with python 2.5 and 2.6, but doesn't work with python 2.7 (Unhandled exception at 0x1e001759 in python.exe: 0xC0000005: Access violation reading location 0x00000010.) Function __getInterf...

Python: Can we convert a ctypes structure to a dictionary ?

Hi all I have a ctypes structure. class S1 (ctypes.Structure): _fields_ = [ ('A', ctypes.c_uint16 * 10), ('B', ctypes.c_uint32), ('C', ctypes.c_uint32) ] if I have X=S1(), I would like to return a dictionary out of this object: Example, if I do something like: Y = X.getdict() or Y = getdict(X), then Y ...

Python ctypes: Python file object <-> C FILE *

Hello, I am using ctypes to wrap a C-library (which I have control over) with Python. I want to wrap a C-function with declaration: int fread_int( FILE * stream ); Now; I would like to open file in python, and then use the Python file-object (in some way??) to get access to the underlying FILE * object and pass that to the C-function...

using python.ctypes with cygwin

I want to use python's (2.6.5) ctypes with cygwin, but I don't know how to load a dll. I tried various variants like >>> form ctypes import * >>> cdll.LoadLibrary("/lib/libcairo.dll.a") Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python2.6/ctypes/__init__.py", line 431, in LoadLibrary r...

Raise child_exception Errno 2

I'm attempting to convert a C header into a Python library using ctypes and ctypeslib. I'm running Python 2.7, on OSX 10.6.4 (Snow Leopard). The header-file I am converting is mcbcio32.h, located in /header/mcbcio32.h I wish to create an xml output in the same folder, named mcbcio32.xml. I run h2xml.py (which converts the c header into ...

Interacting with a c struct containing only function pointers using ctypes in python

Hi, I have a struct in a dll that only contains function pointers (ie a vtable) that I would like to interact with in python (for test purposes). I am having a bit of trouble working out how to do this using ctypes. What I have is: struct ITest { virtual char const *__cdecl GetName() = 0; virtual void __cdecl SetName(c...

libgeos_c-1.dll can't be loaded by Python

I'm building my first GeoDjango project but I'm kinda desperate. I'v installed PostgreSQL 9 and PostGis 1.5 through one-click installer on Windows. So everthing is there. I set GEOS_LIBRARY_PATH to the full path of libgeos_c-1.dll in settings.py. But when I run manage.py syncdb, I encounter the following errors: File "C:\Python25\lib...

pointer on ctypes to use opencv on Python 3.1

Hi, i try to use OpenCV on Python 3.1 through ctypes, but I do not know how represent pointers. Example, if I want to load an image and print the content of her first pixel, i will write in C++ : #include <opencv/cv.h> #include <opencv/highgui.h> using namespace std; int main() { IplImage *img; img = cvLoadImage("/home/foo/f...

translating arrays from c to python ctypes

I have the below arrays on C how can i interpert them to ctypes datatypes inside structre struct a { BYTE a[30]; CHAR b[256]; }; should i interpert a fixed array as the datatype * the size i want like the below and if yes how can i call this structure as a parameter to fun that takes instance from this structure class a(st...

Python reference count and ctypes

Hallo, I have some troubles understanding the python reference count. What I want to do is return a tuple from c++ to python using the ctypes module. C++: PyObject* foo(...) { ... return Py_BuildValue("(s, s)", value1, value2); } Python: pointer = c_foo(...) # c_foo loaded with ctypes obj = cast(pointer, py_object).value I'm...

C / Python ctypes shared object introspection libraries/techniques.

Hi, I was looking for a way to list .text section defined symbols on a C shared object loaded on a python program using the ctypes wrapper. In other words, i am trying to get a list of defined functions on a CDLL loaded object. If there is no way to do this with ctypes or library ( or python binding ), another option is a python elf pa...

Python differences between running as script and running via interactive shell

I am attempting to debug a problem with a ctypes wrapper of a windows DLL and have noticed differences when I run tests via an interactive shell (python or ipython) and when I run the scripts non-interactively. I was wondering if there is any explanation for the differences I am seeing here? Specifically, when I interactively run a sim...

python ctypes.create_string_buffer help!!!!

hey all, i have been scanning the net for answers to this question for days now and im still making no progress so i beg for your help oh mighty guru's of computer wisdom :) my problem is my readprocessmemory function is returning unicode.. here is my code kernel32 = ctypes.windll.kernel32 PROCESS_QUERY_INFORMATION = 0x0400 PROCESS_VM_...