Python获取 当前目录、上一级目录
文章目录
import os print '\*\*\*获取当前目录\*\*\*' print os.getcwd() print os.path.abspath(os.path.dirname(\_\_file\_\_)) print '\*\*\*获取上级目录\*\*\*' print os.path.abspath(os.path.dirname(os.path.dirname(\_\_file\_\_))) print os.path.abspath(os.path.dirname(os.getcwd())) print os.path.abspath(os.path.join(os.getcwd(), "..")) print '\*\*\*获取上上级目录\*\*\*' print os.path.abspath(os.path.join(os.getcwd(), "../.."))
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论