Why does lib.__dict__(vars) only show an object after runnning hasattr or getattr?

54 Views Asked by At

Here is the example code:

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))

The result is:

{'EVP_get_cipherbyname': <_FuncPtr object at 0x7f1b30835048>, '_handle': 21221024, '_name': 'libcrypto.so.1.0.0', '_FuncPtr': <class 'ctypes.CDLL.__init__.<locals>._FuncPtr'>}

I found if the code without the line

hasattr(lib, 'EVP_get_cipherbyname')

the print result is below which doesn't include the 'EVP_get_cipherbyname'

{'_name': 'libcrypto.so.1.0.0', '_handle': 24407408, '_FuncPtr': <class 'ctypes.CDLL.__init__.<locals>._FuncPtr'>}

Could someone explain why?

0

There are 0 best solutions below