def get_func(libname, funcname, restype=None, argtypes=()):
    """Retrieve a function from a library, and set the data types."""
    from ctypes import cdll

    lib = cdll.LoadLibrary(libname)
    func = getattr(lib, funcname)
    func.argtypes = argtypes
    func.restype = restype

    return func
Retrieve a function from a library, and set the data types.
recipes/Python/577655_POSIX_Semaphore_FreeBSD/recipe-577655.py