python导入上两级目录文件_如何在两个子目录中导入python文件

本文解析了Python中当尝试导入名为'spam'的模块时,解释器如何首先查找内置模块,然后搜索sys.path指定的目录列表。重点介绍了sys.path的初始化来源,包括输入脚本目录、PYTHONPATH和安装依赖默认路径,以及后续的动态修改方式。
摘要由CSDN通过智能技术生成

6.1.2. The Module Search Path

When a module named spam is imported, the interpreter first searches

for a built-in module with that name. If not found, it then searches

for a file named spam.py in a list of directories given by the

variable sys.path. sys.path is initialized from these locations:

the directory containing the input script (or the current directory).

PYTHONPATH (a list of directory names, with the same syntax as the

shell variable PATH).

the installation-dependent default.

After initialization, Python programs can modify sys.path.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值