繁体   English   中英

python:导入功能在 3.5 中不起作用

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM