python 基础 —— 获取文件路径

来源:互联网 发布:diy耳放 淘宝 靠谱么 编辑:程序博客网 时间:2024/06/08 06:52

这里写图片描述

# -*- coding:utf-8 -*-import osimport sys# 当前文件在系统中的绝对路径print(os.path.abspath(__file__))# 上级目录print(os.path.pardir)# 当前文件及兄弟文件(夹)print(os.path.join(os.path.dirname(__file__), os.path.pardir))# 当前文件所在的目录print(os.path.dirname(os.path.abspath(__file__)))# 当前文件所在目录的上级目录print(os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)))
0 0
原创粉丝点击