June 2017
Beginner to intermediate
274 pages
6h 49m
English
If we're planning on making systematic use of a foreign function, or especially, if we're going to expose it as part of the interface of a module we're writing, it is advisable to tell ctypes about the function's signature. We can do this by assigning to the function's argtypes and restype attributes.
The argtypes attribute should be a list of C data types defined in the ctypes package, while restype should be one of these packages, as shown in the following code example:

As you can see in the code, providing this information to ctypes significantly improves the error handling of a foreign function. The ...
Read now
Unlock full access