码迷,mamicode.com
首页 > 其他好文 > 详细

os路径问题

时间:2019-11-29 13:06:37      阅读:74      评论:0      收藏:0      [点我收藏+]

标签:dir   abs   目录   tin   bsp   文件   set   linux   getc   

import os 

linux下
例如: 我现在在 /home/settings.py文件下

# 获取当前的绝对路径
os.path.abspath(__file__) # 获取的内容 /home/settings.py
# 获取当前路径的上一级目录
os.path.dirname(os.path.abspath(__file__))

os.getcwd()
# 获取的内容 /home
window下
例如: 我现在在 F:\Futbin\settings.py文件下

# 获取当前的绝对路径
os.path.abspath(__file__)  # 获取的内容 F:\Futbin\settings.py
 
# 获取当前路径的上一级目录

os.path.dirname(os.path.abspath(__file__))
或
os.getcwd()
# 获取的内容  F:\Futbin

或
os.path.dirname(__file__)  # 只能在windows下这么用,在linux下打印不出来的
#获取的内容  F:/Futbin

 

 

os路径问题

标签:dir   abs   目录   tin   bsp   文件   set   linux   getc   

原文地址:https://www.cnblogs.com/smile-tree/p/11956886.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!