我用它来导入 2.7 中的一个函数,该函数有效:
def import_x():
import os
import imp
directory = os.path.dirname(os.path.realpath(__file__))
os.environ['__PYTHON_SYS_PATH_FOR_TESTFOLDER__'] = directory
fp, pathname, description = imp.find_module('test', [ directory ])
if fp is not None:
try:
x = imp.load_module('test', fp, os.path.realpath(pathname), description)
finally:
fp.close()
return x
test = import_x()
但我很难在 3.5 中完成这项工作。请问有什么想法吗?