os模块的常用方法

os模块常用方法
方法说明
os.getcwd()获取当前位置的绝对路径
os.listdir(path)获取path路径下的所有文件和文件夹(path必须是文件夹路径,如果是个文件会报错)
os.chdir(path)Change the current working directory to path
os.mkdir(pathmode=0o777)Create a directory named path with numeric(数字的) mode mode.
os.makedirs(path,mode=0o777)Create recursive(递归的) directory
os.rmdir(path)Remove (delete) the directory path. Only works when the directory is empty, otherwise, OSError is raised.
os.removedirs(path)递归的删除目录(所有目录必须是空的,否则会抛出错误)
os.rename(srcdst)Rename the file or directory src to dst.
os.system(command)Execute the command (a string) in a subshell.
os.getenv(keydefault=None)Return the value of the environment variable key if it exists, or default if it doesn’t. keydefault and the result are str.
os.path
os.path.isfile(path)判断是否是一个文件
os.path.isdir(path)判断是否是一个路径
os.path.islink(path)判断是否是一个链接
os.path.join(pathA,pathB)自动组合路径
os.path.exists(path)Return True if path refers to an existing path or an open file descriptor(描述符). Returns False for broken(断开的) symbolic links.

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值