以下是示例代码:
import ctypes.util
from ctypes import CDLL
path = ctypes.util.find_library('crypto')
lib = CDLL(path)
hasattr(lib, 'EVP_get_cipherbyname') #only run this line or getattr,
#the print(lib.__dict__) show the EVP_get_cipherbyname
print(lib.__dict__)
print(vars(lib))
结果是:
{'EVP_get_cipherbyname': <_FuncPtr object at 0x7f1b30835048>, '_handle': 21221024, '_name': 'libcrypto.so.1.0.0', '_FuncPtr': <class 'ctypes.CDLL.__init__.<locals>._FuncPtr'>}
我发现代码中没有行
hasattr(lib, 'EVP_get_cipherbyname')
打印结果低于'EVP_get_cipherbyname'
{'_name': 'libcrypto.so.1.0.0', '_handle': 24407408, '_FuncPtr': <class 'ctypes.CDLL.__init__.<locals>._FuncPtr'>}
有人可以解释原因吗?