python 标准库之os

来源:互联网 发布:淘宝猫粮店推荐 编辑:程序博客网 时间:2024/05/21 22:26

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

0 0