[英]python: import function doesnt work in 3.5
我用它來導入 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 中完成這項工作。 請問有什么想法嗎?
試試這個:
import sys
directory = os.path.dirname(os.path.abspath(sys.argv[0]))
我不確定具體的變化,但這似乎有效。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.