import ctypes libc ctypes cdll("/usr/lib/libc dylib"libc rand( libc atoi(" " in this exampleoperations such as libc rand(and libc atoi(are directly calling functions in the loaded library ctypes assumes that all functions accept parameters of type int or char and return results of type int thuseven though the previous function calls "worked,calls to other library functions do not work as expected for examplelibc atof(" "- to address this problemthe type signature and handling of any foreign function func can be set by changing the following attributesfunc argtypes tuple of ctypes datatypes (described heredescribing the input arguments to func func restype ctypes datatype describing the return value of func none is used for functions returning void func errcheck python callable object taking three parameters (resultfuncargswhere result is the value returned by foreign functionfunc is reference to the foreign function itselfand args is tuple of the input arguments this function is called after foreign function call and can be used to perform error checking and other actions here is an example of fixing the atof(function interfaceas shown in the previous examplelibc atof restype=ctypes c_double libc atof(" " the ctypes d_double is reference to predefined datatype the next section describes these datatypes datatypes table shows the ctypes datatypes that can be used in the argtypes and restype attributes of foreign functions the "python valuecolumn describes the type of python data that is accepted for the given data type lib fl ff