Python3 导入上级目录中的模块实例
作者:极客点儿 时间:2023-09-01 02:25:20
python导入同级别模块很方便:
import xxx
要导入下级目录页挺方便,需要在下级目录中写一个__init__.py文件
from dirname import xxx
要导入上级目录,可以使用 sys.path
首先 sys.path 的作用是:当使用import语句导入模块时,解释器会搜索当前模块所在目录以及sys.path指定的路径去找需要import的模块
所以改变思路,直接把上级目录加到 sys.path 里
import sys
sys.path.append('../')
from fatherdirname import xxx
来源:https://blog.csdn.net/yilovexing/article/details/81584629
标签:Python3,导入,目录,模块
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python socket多线程通讯实例分析(聊天室)
2022-11-21 13:18:58
JavaScript 在各个浏览器中执行的耐性
2009-02-06 15:26:00
再谈float菜单局中
2009-12-21 19:57:00
python基于turtle绘制几何图形
2023-06-22 22:44:43
![](https://img.aspxhome.com/file/2023/7/135237_0s.png)
python中的Json模块dumps、dump、loads、load函数用法详解
2023-11-09 20:01:30
![](https://img.aspxhome.com/file/2023/7/105417_0s.png)
Mysql json类型字段Java+Mybatis数据字典功能的实践方式
2024-01-22 00:24:34
![](https://img.aspxhome.com/file/2023/3/71243_0s.jpg)
python的多元数据类型(下)
2023-06-17 02:45:11
![](https://img.aspxhome.com/file/2023/5/117575_0s.jpg)
Java正则表达式循环匹配字符串方式
2023-07-25 03:29:48
![](https://img.aspxhome.com/file/2023/9/70279_0s.png)
python3+PyQt5 实现Rich文本的行编辑方法
2023-09-29 14:37:47
VUE中的export default和export使用方法解析
2024-06-05 09:14:22
详解Python中的测试工具
2022-07-02 09:10:13
python实现简单学生信息管理系统
2022-01-28 12:40:00
![](https://img.aspxhome.com/file/2023/0/112750_0s.jpg)
基于Python绘制一个摸鱼倒计时界面
2022-09-02 03:03:26
![](https://img.aspxhome.com/file/2023/7/115407_0s.jpg)
python 实现围棋游戏(纯tkinter gui)
2023-11-23 16:13:04
![](https://img.aspxhome.com/file/2023/4/92074_0s.gif)
Oracle 数据显示 横表转纵表
2024-01-22 23:35:05
ASP获取当前页面URL地址(带参数)的方法
2010-01-14 19:40:00
Anaconda下安装mysql-python的包实例
2024-01-25 08:04:29
![](https://img.aspxhome.com/file/2023/0/89050_0s.jpg)
利用Python如何生成便签图片详解
2021-01-02 18:09:52
![](https://img.aspxhome.com/file/2023/1/80441_0s.png)
如何在PyCharm中配置使用Anaconda环境
2021-01-28 14:16:53
![](https://img.aspxhome.com/file/2023/6/112596_0s.jpg)
python中random模块详解
2023-07-30 02:29:23
![](https://img.aspxhome.com/file/2023/1/61211_0s.png)