1

这是示例代码:

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'>}

有人可以解释为什么吗?

4

0 回答 0