多路径引入模块问题

1、目录

use_model.py是主源代码,model_1.py是需要引入的模块,放在test文件夹里

在model_1.py里

def add(a,b):
    return a+b

def dec(a,b):
    return a-b
    
HEAD = "55AA"

2、在model_1.py那里新建一个__init__.py文件【空的】

3、在use_model.py里

import sys
sys.path.append("..")
import test.model_1

print("")
if __name__ == "__main__":
    print(test.model_1.add(2,3))
    print(test.model_1.dec(3,2))
    print(test.model_1.HEAD)

猜你喜欢

转载自www.cnblogs.com/judes/p/9979241.html