我正在尝试在python中加载一个dll,并且只有在我输入绝对路径时才能这样做。我想使用相对路径或环境变量。唯一有效的是如果我指定确切的路径(C:...)我甚至试图让dll直接在与py文件相同的文件夹中构建,它仍然无效。
我有什么:
MY_DLL = r'c:\full_path\output\Win32\Debug\my.dll'
#MY_DLL = r'my.dll' #this doesn't work but it is what I want
#MY_DLL = r'$(env_var)\dir\output\$(Platform)\$(Configuration)\my.dll' #this doesn't work either but would be good too
帮助?
答案 0 :(得分:1)
我不知道windows上的cdll或者一般的ctypes,但是,你可以使用os.path很容易地操作路径:
import os.path
p1="path.dll"
print (os.path.abspath(p1))
p2="${env_var}/path.dll" #Make sure you set env_var in the calling environment...Otherwise it won't be expanded...
print (os.path.expandvars(p2))