0
点赞
收藏
分享

微信扫一扫

Python 文件及文件夹操作记录


# coding=utf-8

import os, sys

# 文件目录的斜杠,使平台无关
print os.sep

# 回到上级目录
print os.path.pardir
print os.path.join(os.path.dirname("__file__"), os.path.pardir)

# ----------------------------------------------------------------------------------------------

# 获取文件当前路径
print os.path.dirname(os.path.abspath("__file__"))
print sys.path[0]
print os.getcwd()

# 获得文件上级目录
print os.path.abspath(os.path.join(os.path.dirname("__file__"), os.path.pardir))

# 获取指定目录下说有文件和目录名
print os.listdir(os.getcwd())

# 分离扩展名
print os.path.splitext(os.getcwd())

# 获取路径名
print os.path.dirname(os.getcwd())

# 获取文件名
print os.path.basename(os.getcwd())


举报

相关推荐

0 条评论