I have a Python import that is a wrapper for a legacy Windows DLL; the import declares a number of interface functions/wrappers for functions in the DLL (mostly to handle data type differences).
I’d like to be able to externally control which DLL the import loads; something like this:
if environment == 'release':
mydll = ctypes.cdll.LoadLibrary('../DLL/x64/Release/scanner64.dll')
elif environment == 'debug':
mydll = ctypes.cdll.LoadLibrary('../DLL/x64/Debug/scanner64.dll')
elif environment == 'local':
mydll = ctypes.cdll.LoadLibrary('./Scanner64.dll')
else:
print("Valid environments are release, debug, and local")
exit()
I’ve tried declaring ‘environment’ as global in my main Python script, but that doesn’t work. I also tried putting the majority of the contents of the import in an init() funciton, but that doesn’t work either (as the scope of the function defs is within the init function–not visible to the importing script.
Bentley is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.