python 标准库之os

os.walk()
这个函数yield一个3-tuple(dirpath, dirnames, filenames)
解释
dirnames is a list of the names of the subdirectories in dirpath (excluding ‘.’ and ‘..’).
filenames is a list of the names of the non-directory files in dirpath. Note that the names in the lists contain no path components. To get a full path (which begins with top) to a file or directory in dirpath, do os.path.join(dirpath, name).

os.getcwd()
或者linux里面的pwd命令
和os.path.dirname()的区别
起因为binscope会在当前工作目录下产生一个log,而我要把这个删掉,但是我起初没有当前工作目录的概念。
工作目录并不是当前文件所在的目录—这点要注意

获取根目录下的文件和目录的绝对路径
[os.path.join(‘/’, path) for path in os.listdir(‘/’)]

获取绝对路径
os.path.abspath(__file__)

进程相关os
os.execv(path, arglist)
取代当前的进程
Execute an executable path with arguments, replacing current process.
path: path of executable file
args: tuple or list of strings
os.getpid()
当前的进程pid

转载于:https://www.cnblogs.com/lineuman/p/6775978.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值