ctypes is a foreign function library for Python. It provides C compatible data types, and allows calling functions in DLLs or shared libraries. It can be used to wrap these libraries in pure Python.
ctypes is the de facto standard library for interfacing with C/C++ from CPython, and it provides not only full access to the native C interface of most major operating systems (e.g., kernel32 on Windows, or libc on *nix), but also provides support for loading and interfacing with dynamic libraries, such as DLLs or ...
c_char_p is a subclass of _SimpleCData , with _type_ == 'z' . The __init__ method calls the type's setfunc , which for simple type 'z' is z_set . In Python 2, the z_set function (2.7. 7) is written to handle both str and unicode strings.
Definition of cubit : any of various ancient units of length based on the length of the forearm from the elbow to the tip of the middle finger and usually equal to about 18 inches (46 centimeters)
I have a Python 2.7 GUI for interacting with a C library. I do a bunch of setup in the GUI, then I press "go" button. Then, I'm looking at results and no longer need the library code. But I would like to keep all the GUI state while changing the library.
I import the so
or dll
with ctypes
, which obviously opens the file for reading. But, I'd like to explicitly close the file in order to recompile and overwrite it. Then, when I press the "go" button again, I'd like to import the new version.
In the worst case scenario, I could copy the file to a tempfile.NamedTemporaryFile
, but then I have handles open to dozens of files, none of which I can clean up.
Can I somehow explicitly close the file handle? Or, can I read the contents of the file into a StringIO
object and somehow point ctypes
at that?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With