Answer the question
In order to leave comments, you need to log in
Does it matter which approach to use, from a Python point of view?
Hello. There is code that does the same thing. Is there a difference from a python point of view? Or you can use it however you like.
lib = ctypes.CDLL(path)
def WrapFunction(lib, funcname, restype, argtypes):
func = lib.__getattr__(funcname)
func.restype = restype
func.argtypes = argtypes
return func
# первый вариант
CTestFunc = WrapFunction(lib,'TestFunc',None,[c_int,c_int,POINTER(ctypes.c_char)])
def TestFunc(int_width, int_height, str_title):
return CTestFunc(int_width, int_height, str_title.encode('utf-8'))
# или такой вариант (мне он больше нравится).
def TestFunc(int_width, int_height, str_title):
TestFunc = WrapFunction(lib,'TestFunc',None,[c_int,c_int,POINTER(ctypes.c_char)])
return TestFunc(int_width, int_height, str_title.encode('utf-8'))
# Знаю про PEP-8, но мне для обратной совместимости так удобнее. Называть функции.
# Подскажите пожалуйста есть ли разница? Для производительности, около 200 таких враперов.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question