这是我用来导入任何东西的东西。当然,您仍然必须将此脚本复制到本地目录,导入它以及use
您想要的路径。
import sys
import os
# a function that can be used to import a python module from anywhere - even parent directories
def use(path):
scriptDirectory = os.path.dirname(sys.argv[0]) # this is necessary to allow drag and drop (over the script) to work
importPath = os.path.dirname(path)
importModule = os.path.basename(path)
sys.path.append(scriptDirectory+"\\"+importPath) # Effing mess you have to go through to get python to import from a parent directory
module = __import__(importModule)
for attr in dir(module):
if not attr.startswith('_'):
__builtins__[attr] = getattr(module, attr)