python 标准库之os
发布日期:2021-05-07 18:06:25 浏览次数:22 分类:精选文章

本文共 819 字,大约阅读时间需要 2 分钟。

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

上一篇:what's the difference between atime, ctime and mtime
下一篇:pexpect

发表评论

最新留言

不错!
[***.144.177.141]2025年04月10日 10时45分26秒