Let's say if I have a dll
file called banana.dll
, and I have a module called banana.py
which will use ctypes
to load banana.dll
, and they are stored in the same directory, for exmaple c:\Python27\lib
in Windows.
Now I create a new python file called testing.py
in other directory (for example c:\user\desktop
) which will import the banana.py
module. But since the current working directory is the directory where testing.py
is stored. So I need to manually change the directory to c:\Python27\lib
by hardcoding it.
But is there a smarter way that I can search the path where banana.dll
is stored?
If you have pywin32 installed:
Or
If you don't have pywin32, you can use ctypes to access win32 api:
Don't forget to handle WindowsError and other possible exceptions.
Try: