python中获得当前目录和上级目录的实现方法
作者:悠然现南山 时间:2022-01-07 20:24:30
获取当前文件的路径:
from os import path
d = path.dirname(__file__) #返回当前文件所在的目录
# __file__ 为当前文件, 若果在ide中运行此行会报错,可改为 #d = path.dirname('.')
获得某个路径的父级目录:
parent_path = os.path.dirname(d) #获得d所在的目录,即d的父级目录
parent_path = os.path.dirname(parent_path) ##获得parent_path所在的目录即parent_path的父级目录
获得规范的绝对路径:
abspath = path.abspath(d) #返回d所在目录规范的绝对路径
总结
以上所述是小编给大家介绍的python中获得当前目录和上级目录的实现方法网站的支持!
来源:http://www.cnblogs.com/yrxns/p/7654771.html
标签:python,当前目录,上级目录
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
立足于传统行业设计
2008-07-26 12:36:00
tensorflow可视化Keras框架中Tensorboard使用示例
2023-08-09 01:39:27
![](https://img.aspxhome.com/file/2023/2/64692_0s.png)
利用Python正则表达式过滤敏感词的方法
2023-05-07 05:05:18
![](https://img.aspxhome.com/file/2023/0/95310_0s.jpg)
mssql 大小写区分方法
2008-12-29 14:08:00
Python逐行读取文件中内容的简单方法
2023-03-02 16:01:09
![](https://img.aspxhome.com/file/2023/9/79689_0s.jpg)
做网站要习惯化与去习惯化
2008-06-18 13:36:00
python接入使用百度翻译流程
2022-11-26 01:01:43
![](https://img.aspxhome.com/file/2023/1/71571_0s.png)
python概率计算器实例分析
2021-01-16 05:34:52
python绘制字符画视频的示例代码
2023-11-09 16:21:46
![](https://img.aspxhome.com/file/2023/7/63957_0s.jpg)
ASP.NET Core Authentication认证实现方法
2023-07-21 12:21:31
![](https://img.aspxhome.com/file/2023/8/78078_0s.jpg)
PHP二维码的生成与识别案例
2023-06-14 06:48:55
![](https://img.aspxhome.com/file/2023/2/55562_0s.png)
python多线程分块读取文件
2023-10-29 18:48:51
Python 用__new__方法实现单例的操作
2023-05-22 08:22:41
python使用Word2Vec进行情感分析解析
2023-10-29 21:16:47
![](https://img.aspxhome.com/file/2023/8/72248_0s.gif)
ASP+SQLServer2000 经验积累
2008-02-03 15:16:00
Python的字符串操作简单实例
2021-03-13 07:16:00
Django 项目布局方法(值得推荐)
2022-08-22 12:44:22
Python Pandas高级教程之时间处理
2021-08-12 14:04:49
成为一个顶级设计师的第一准则
2008-04-18 10:29:00
![](https://img.aspxhome.com/file/UploadPic/20084/18/2008418103351248s.jpg)
Mootools常用方法扩展(五)
2009-03-03 12:12:00