标签: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
标签:dir abs 目录 tin bsp 文件 set linux getc
原文地址:https://www.cnblogs.com/smile-tree/p/11956886.html