1,主程序与模块在同一路径下

python的import用法

在程序testGetCRStatement.py中导入模块custom, 则直接使用import custom或from custom import *;

2, 程序所在目录是模块所在目录的父(或祖辈)目录


python的import用法

python的import用法


程序runAll.py中导入评级目录common下的log模块,需要在common下创建一个空文件__init__.py,然后使用 import common.log as log

3,主程序导入上层目录中或其他目录(平级)下模块

python的import用法

python的import用法


python的import用法

若在程序log.py中导入模块readConfig.py。首先需要在config下建立__init__.py文件,src下不必建立该文件。然后调用方式如下:

import sys

sys.path.append("..")

import config.readConfig as readConfig








相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-01
  • 2023-03-07
  • 2022-01-13
  • 2021-12-28
  • 2021-07-26
猜你喜欢
  • 2021-12-19
  • 2022-12-23
  • 2021-11-05
  • 2022-12-23
  • 2022-12-23
  • 2021-12-19
相关资源
相似解决方案