一图看懂 os 模块:基本操作系统功能,包括文件操作, 资料整理+笔记(大全)

本文由 大侠(AhcaoZhu)原创,转载请声明。
链接: https://blog.csdn.net/Ahcao2008

Alt

一图看懂 os 模块:基本操作系统功能,包括文件操作, 资料整理+笔记(大全)

  • 摘要
  • 模块
  • 模块全展开
  • 统计
  • 【os】
  • 常量
    • int
    • bool
    • str
    • set
  • 模块
    • 43 abc
    • 44 sys
    • 45 stat
    • 46 ntpath
  • 函数
    • 47 _check_methods(C, *methods)
    • 48 _exists(name)
    • 49 _get_exports_list(module)
    • 50 makedirs(name, mode=511, exist_ok=False)
    • 51 removedirs(name)
    • 52 renames(old, new)
    • 53 walk(top, topdown=True, οnerrοr=None, followlinks=False)
    • 54 execl(file, *args)
    • 55 execle(file, *args, env)
    • 56 execlp(file, *args)
    • 57 execlpe(file, *args)
    • 58 execvp(file, args)
    • 59 execvpe(file, args, env)
    • 60 _execvpe(file, args, env=None)
    • 61 get_exec_path(env=None)
    • 62 (key)
    • 63 getenv(key, default=None)
    • 64 fsencode(filename)
    • 65 fsdecode(filename)
    • 66 spawnl(mode, file, *args)
    • 67 spawnle(mode, file, *args)
    • 68 popen(cmd, mode='r', buffering=-1)
    • 69 fdopen(fd, *args, **kwargs)
    • 70 _fspath(path)
    • 71 OSError
      • data
    • 72 os.stat_result
      • data
    • 73 os.statvfs_result
      • data
    • 74 nt.times_result
      • data
    • 75 nt.uname_result
      • data
    • 76 os.terminal_size
      • data
    • 77 nt.DirEntry
      • data
      • method
      • 3 inode(self, *args, **kwargs)
      • 4 is_dir(self, *args, **kwargs)
      • 5 is_file(self, *args, **kwargs)
      • 6 is_symlink(self, *args, **kwargs)
      • 7 stat(self, *args, **kwargs)
    • 78 collections.abc.MutableMapping
      • method
      • 1 clear()
      • 2 pop()
      • 3 popitem()
      • 4 setdefault()
      • 5 update()
    • 79 os._Environ
      • method
      • 1 copy(self)
      • 2 setdefault(self, key, value)
    • 80 os._wrap_close
      • method
      • 1 close(self)
    • 81 os.PathLike
  • 内嵌函数或方法
  • 私有或局部
  • 剩余
  • 统计
  • 【ntpath】
  • 常量
    • bool
    • str
  • 模块
    • 10 os
    • 11 sys
    • 12 stat
    • 13 genericpath
  • 函数
    • 14 commonprefix(m)
    • 15 exists(path)
    • 16 getatime(filename)
    • 17 getctime(filename)
    • 18 getmtime(filename)
    • 19 getsize(filename)
    • 20 isfile(path)
    • 21 samefile(f1, f2)
    • 22 sameopenfile(fp1, fp2)
    • 23 samestat(s1, s2)
    • 24 _get_bothseps(path)
    • 25 normcase(s)
    • 26 isabs(s)
    • 27 join(path, *paths)
    • 28 splitdrive(p)
    • 29 split(p)
    • 30 splitext(p)
    • 31 basename(p)
    • 32 dirname(p)
    • 33 islink(path)
    • 34 lexists(path)
    • 35 ismount(path)
    • 36 expanduser(path)
    • 37 expandvars(path)
    • 38 normpath(path)
    • 39 _abspath_fallback(path)
    • 40 abspath(path)
    • 41 abspath(path)
    • 42 relpath(path, start=None)
    • 43 commonpath(paths)
  • 内嵌函数或方法
  • 私有或局部
  • 【sys】
  • 【stat】
  • 常量
    • int
    • tuple
  • 内嵌函数或方法
  • 私有或局部
  • 统计
  • 【genericpath】
  • 模块
    • 1 os
    • 2 stat
  • 函数
    • 3 exists(path)
    • 4 isfile(path)
    • 5 isdir(s)
    • 6 getsize(filename)
    • 7 getmtime(filename)
    • 8 getatime(filename)
    • 9 getctime(filename)
    • 10 commonprefix(m)
    • 11 samestat(s1, s2)
    • 12 samefile(f1, f2)
    • 13 sameopenfile(fp1, fp2)
    • 14 _splitext(p, sep, altsep, extsep)
    • 15 _check_arg_types(funcname, *args)
  • 私有或局部

摘要

全文介绍系统内置 os 模块(包含 os.path 模块)、函数、类及类的方法和属性。
它通过代码抓取并经AI智能翻译和人工校对。
是一部不可多得的权威字典类工具书。它是系列集的一部分。后续陆续发布、敬请关注。【原创:AhcaoZhu大侠】

模块

一图看懂 os 模块:基本操作系统功能,包括文件操作, 资料整理+笔记(大全)_第1张图片

os
	◆abc
	◆sys
	◆stat
	◆ntpath

一图看懂 os 模块:基本操作系统功能,包括文件操作, 资料整理+笔记(大全)_第2张图片

◆object
	◆abc.ABC
		os.PathLike
	◆collections.abc.Container
		◆collections.abc.Iterable
			◆collections.abc.Sized
				◆collections.abc.Collection
					◆collections.abc.Mapping
						◆collections.abc.MutableMapping
							os._Environ
	os._wrap_close
	◆tuple
		os.stat_result
		os.statvfs_result
		os.terminal_size

模块全展开

统计

序号 类别 数量
1 int 27
2 bool 1
4 str 15
6 list 1
7 set 4
8 dict 1
9 module 4
10 class 11
11 function 24
12 builtin_function_or_method 60
13 residual 3
14 system 9
15 private 10
16 all 151

【os】

os, fullname=os, file=os.py

NT或Posix的操作系统例程,这取决于我们使用的是什么系统。
这将输出:
    - posix或nt中的所有函数,例如unlink, stat等。
    - os.path为posixpath或ntpath
    - os.name为'posix'或'nt'
    - os.curdir是一个表示当前目录的字符串(总是'.')
    - os.pardir是一个字符串,表示父目录(总是'..')
    - os.sep是(或最常见的)路径名分隔符('/'或'\\')
    - os.extsep是扩展分隔符(总是'.')
    - os.altsep是替代路径名分隔符(None或'/')
    - os.pathsep是在$PATH等操作系统中使用的组件分隔符。
    - os.linesep是文本文件中的行分隔符('\r'或'\n'或'\r\n')
    - os.defpath是可执行文件的默认搜索路径
    - os.devnull是空设备('/dev/null'等)的文件路径。
导入并使用'os'的程序更有可能在不同平台之间移植。当然,他们必须只使用由所有平台定义的函数(例如unlink和opendir),并将所有路径名操作留给os。
路径(例如,split分割和join连接)。

常量

int

1 F_OK 0
2 R_OK 4
3 W_OK 2
4 X_OK 1
5 TMP_MAX 2147483647
6 O_RDONLY 0
7 O_WRONLY 1
8 O_RDWR 2
9 O_APPEND 8
10 O_CREAT 256
11 O_EXCL 1024
12 O_TRUNC 512
13 O_BINARY 32768
14 O_TEXT 16384
15 O_NOINHERIT 128
16 O_SHORT_LIVED 4096
17 O_TEMPORARY 64
18 O_RANDOM 16
19 O_SEQUENTIAL 32
20 P_WAIT 0
21 P_NOWAIT 1
22 P_OVERLAY 2
23 P_NOWAITO 3
24 P_DETACH 4
25 SEEK_SET 0
26 SEEK_CUR 1
27 SEEK_END 2

bool

28 supports_bytes_environ False

str

29 name nt
30 linesep \n
31 curdir .
32 pardir …
33 sep
34 pathsep ;
35 defpath .;C:\bin
36 extsep .
37 altsep /
38 devnull nul

set

39 supports_dir_fd set()
40 supports_effective_ids set()
41 supports_fd {, }
42 supports_follow_symlinks {}

模块

43 abc

abc, fullname=abc, file=abc.py

根据PEP 3119的抽象基类(abc)。

44 sys

sys, fullname=sys, file=

参见:sys 模块

45 stat

stat, fullname=stat, file=stat.py

用于解释os.stat()和os.lstat()结果的常量/函数。建议使用:from stat import *

46 ntpath

ntpath, fullname=ntpath, file=ntpath.py

常见的路径名操作,WindowsNT/95版本。不要直接导入这个模块,而是导入os并将这个模块引用为os.path。

函数

47 _check_methods(C, *methods)

_check_methods(C, *methods), module=collections.abc, line:72 at _collections_abc.py

48 _exists(name)

_exists(name), module=os, line:39 at os.py

49 _get_exports_list(module)

_get_exports_list(module), module=os, line:42 at os.py

50 makedirs(name, mode=511, exist_ok=False)

makedirs(name, mode=511, exist_ok=False), module=os, line:198 at os.py

makedirs(name [, mode=0o777][, exist ok=False])
超级mkdir;创建一个叶目录和所有中间目录。工作方式类似于mkdir,但是如果中间路径段(不仅仅是最右边的)不存在,则会创建它。
如果目标目录已经存在,如果exist_ok为False则引发OSError。否则不会引发异常。这是递归的。

51 removedirs(name)

removedirs(name), module=os, line:230 at os.py

removedirs(name)
超级-rmdir;删除一个叶目录和所有空的中间目录。工作方式类似于rmdir,不同之处在于,如果成功删除了叶子目录,则与最右侧路径段对应的目录将被删除,
直到整个路径被消耗或发生错误。后一个阶段的错误将被忽略——它们通常意味着目录不是空的。

52 renames(old, new)

renames(old, new), module=os, line:252 at os.py

根据需要创建目录,并删除任何空目录。
工作类似于重命名,除了创建任何中间目录需要使新路径名良好,首先尝试。
重命名后,与旧名称的最右路径段对应的目录将被修剪,直到整个路径被消耗掉或找到一个非空目录。
注意:如果您缺乏解除叶子目录或文件链接所需的权限,则此函数可能会在创建新目录结构时失败。

53 walk(top, topdown=True, οnerrοr=None, followlinks=False)

walk(top, topdown=True, οnerrοr=None, followlinks=False), module=os, line:280 at os.py

	目录树生成器。
	对于目录树中根在top的每个目录(包括top本身,但不包括'.'和'..'),会得到一个三元组:
	    (dirpath, dirnames, filenames)
	    dirpath是一个字符串,表示目录的路径。
	    Dirnames是dirpath中子目录名称的列表(不包括 '.'和'..')。
	    Filenames是dirpath下的非目录文件的名称列表。
	    注意,列表中的名称只是名称,没有路径组件。
    要获取dirpath中的文件或目录的完整路径(以top开始),请执行
        os.path.join(dirpath, name)
    如果可选参数'topdown'为真或未指定,则目录的三元组将在其任何子目录的三元组之前生成(目录将自顶向下生成)。
    如果topdown为false,则目录的三元组在其所有子目录的三元组之后生成(目录是自底向上生成的)。
    当topdown为true时,调用者可以就地修改dirnames列表(例如,通过del或slice赋值),
    walk将只递归到名称仍然在dirnames中的子目录;这可以用来削减搜索,或强加一个特定的访问顺序。
    当topdown为false时,修改 dirnames对os.walk()的行为没有影响,
    因为dirnames中的目录在dirnames本身生成时已经生成了。
    无论topdown的值是多少,在生成目录及其子目录的元组之前,都会检索子目录列表。
    默认情况下,os.scandir()调用的错误将被忽略。
    如果指定了可选参数 'onerror',它应该是一个函数;它将被调用一个参数,一个OSError实例。
    它可以报告错误以继续遍历,也可以引发异常以终止遍历。
    请注意,filename 可用作异常对象的 filename 属性。
    默认情况下,os.walk 不遵循符号链接到支持它们的系统上的子目录。
    为了获得这个功能,将可选参数“followlinks”设置为true。
    注意: 如果你为top传递一个相对路径名,不要改变在 walk 恢复之间的当前工作目录。walk 永不更改当前目录,
    并假设用户也永不更改改。
    举例:
    import os
    from os.path import join, getsize
    for root, dirs, files in os.walk('python/Lib/email'):
        print(root, "consumes", end="")
        print(sum([getsize(join(root, name)) for name in files]), end="")
        print("bytes in", len(files), "non-directory files")
        if 'CVS' in dirs:
            dirs.remove('CVS')  # 不访问 CVS 目录。```

54 execl(file, *args)

execl(file, *args), module=os, line:537 at os.py

执行带有参数列表args的可执行文件,替换当前进程。

55 execle(file, *args, env)

execle(file, *args), module=os, line:544 at os.py

使用参数列表args和环境env执行可执行文件(沿着$PATH搜索),替换当前进程。

56 execlp(file, *args)

execlp(file, *args), module=os, line:552 at os.py

使用参数列表args执行可执行文件(沿着$PATH搜索),替换当前进程。

57 execlpe(file, *args)

execlpe(file, *args), module=os, line:559 at os.py

执行带有参数列表args和环境env的可执行文件,替换当前进程。

58 execvp(file, args)

execvp(file, args), module=os, line:568 at os.py

使用参数列表args执行可执行文件(沿着$PATH搜索),替换当前进程。Args可以是字符串的列表或元组。

59 execvpe(file, args, env)

execvpe(file, args, env), module=os, line:576 at os.py

使用参数列表args和环境env执行可执行文件(沿着$PATH搜索),替换当前进程。Args可以是字符串的列表或元组。

60 _execvpe(file, args, env=None)

_execvpe(file, args, env=None), module=os, line:587 at os.py

61 get_exec_path(env=None)

get_exec_path(env=None), module=os, line:619 at os.py

返回启动进程时搜索已命名可执行文件(类似于shell)的目录序列。*env*必须为环境变量dict或None。
如果*env*为None,则os。将使用Environ。

62 (key)

(key), module=os, line:732 at os.py

63 getenv(key, default=None)

getenv(key, default=None), module=os, line:772 at os.py

获取一个环境变量,如果不存在则返回None。可选的第二个参数可以指定另一个默认值。Key, default和result是str。

64 fsencode(filename)

fsencode(filename), module=os, line:806 at os.py

编码文件名(一个os。使用'surrogateescape'错误处理程序将PathLike, bytes或str)转换为文件系统编码,返回字节不变。
在Windows上,如果文件系统编码是'mbcs'(这是默认编码),则使用'strict'错误处理程序。

65 fsdecode(filename)

fsdecode(filename), module=os, line:818 at os.py

解码文件名(一个os。使用'surrogateescape'错误处理程序从文件系统编码的PathLike, bytes或str)返回str不变。
在Windows上,如果文件系统编码是'mbcs'(这是默认编码),则使用'strict'错误处理程序。

66 spawnl(mode, file, *args)

spawnl(mode, file, *args), module=os, line:927 at os.py

spawn (mode, file, *args) -> integer
使用子进程中的args中的参数执行文件。如果mode == P_NOWAIT返回进程的pid。
如果 mode == P_WAIT如果进程正常退出,则返回进程的退出码;
否则返回-SIG,其中SIG是杀死它的信号。

67 spawnle(mode, file, *args)

spawnle(mode, file, *args), module=os, line:936 at os.py

使用所提供环境的子进程中的args参数执行文件。
如果 mode == P_NOWAIT返回进程的pid。
如果 mode == P_WAIT WAIT如果进程正常退出,则返回进程的退出码;
否则返回-SIG,其中SIG是杀死它的信号。

68 popen(cmd, mode=‘r’, buffering=-1)

popen(cmd, mode=‘r’, buffering=-1), module=os, line:980 at os.py

69 fdopen(fd, *args, **kwargs)

fdopen(fd, *args, **kwargs), module=os, line:1025 at os.py

70 _fspath(path)

_fspath(path), module=os, line:1034 at os.py

返回路径类对象的路径表示形式。如果传入str或bytes,则原样返回。
否则,os.PathLike 接口用于获取路径表示。
如果路径表示形式不是str或bytes,则引发TypeError。
如果提供的路径不是str、bytes或 os.PathLike, TypeError被引发。

71 OSError

OSError, OSError, module=builtins

I/O相关错误的基类。

data

1 characters_written= kind:data type:getset_descriptor class:
2 errno= kind:data type:member_descriptor class:
3 filename= kind:data type:member_descriptor class:
4 filename2= kind:data type:member_descriptor class:
5 strerror= kind:data type:member_descriptor class:
6 winerror= kind:data type:member_descriptor class:

72 os.stat_result

stat_result, os.stat_result, module=os, line:-1 at os.py

stat result: stat、fstat或lstat的结果。
该对象可以作为(mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime)的元组访问,
也可以通过属性 st_mode, st_ino, st_dev, st_nlink, st_uid 等访问。
Posix/windows:如果你的平台支持 st_blksize, st_blocks, st_rdev 或 st_flags,它们只能作为属性使用。
参见:os.stat,获得更多信息。

data

1 n_fields=17 kind:data type:int class:
2 n_sequence_fields=10 kind:data type:int class:
3 n_unnamed_fields=3 kind:data type:int class:
4 st_atime= kind:data type:member_descriptor class:
5 st_atime_ns= kind:data type:member_descriptor class:
6 st_ctime= kind:data type:member_descriptor class:
7 st_ctime_ns= kind:data type:member_descriptor class:
8 st_dev= kind:data type:member_descriptor class:
9 st_file_attributes= kind:data type:member_descriptor class:
10 st_gid= kind:data type:member_descriptor class:
11 st_ino= kind:data type:member_descriptor class:
12 st_mode= kind:data type:member_descriptor class:
13 st_mtime= kind:data type:member_descriptor class:
14 st_mtime_ns= kind:data type:member_descriptor class:
15 st_nlink= kind:data type:member_descriptor class:
16 st_size= kind:data type:member_descriptor class:
17 st_uid= kind:data type:member_descriptor class:

73 os.statvfs_result

statvfs_result, os.statvfs_result, module=os, line:-1 at os.py

statvfs result:来自statvfs或fstatvfs的结果。
该对象可以作为(bsize, frsize, blocks, bfree, bavail, files, ffree, favail, flag, namemax)的元组访问,
也可以通过属性 f_bsize, f_frsize, f_blocks, f_bfree 等访问。
参见:os.statvfs,获得更多信息。

data

1 f_bavail= kind:data type:member_descriptor class:
2 f_bfree= kind:data type:member_descriptor class:
3 f_blocks= kind:data type:member_descriptor class:
4 f_bsize= kind:data type:member_descriptor class:
5 f_favail= kind:data type:member_descriptor class:
6 f_ffree= kind:data type:member_descriptor class:
7 f_files= kind:data type:member_descriptor class:
8 f_flag= kind:data type:member_descriptor class:
9 f_frsize= kind:data type:member_descriptor class:
10 f_fsid= kind:data type:member_descriptor class:
11 f_namemax= kind:data type:member_descriptor class:
12 n_fields=11 kind:data type:int class:
13 n_sequence_fields=10 kind:data type:int class:
14 n_unnamed_fields=0 kind:data type:int class:

74 nt.times_result

times_result, nt.times_result, module=nt

times result: os.times()的结果。
这个对象可以作为(user, system, children_user, children_system, elapsed)的元组访问,
也可以通过属性user, system, children_user, children_system,和elapsed访问。
参见:os.times,获得更多信息。

data

1 children_system= kind:data type:member_descriptor class:
2 children_user= kind:data type:member_descriptor class:
3 elapsed= kind:data type:member_descriptor class:
4 n_fields=5 kind:data type:int class:
5 n_sequence_fields=5 kind:data type:int class:
6 n_unnamed_fields=0 kind:data type:int class:
7 system= kind:data type:member_descriptor class:
8 user= kind:data type:member_descriptor class:

75 nt.uname_result

uname_result, nt.uname_result, module=nt

uname result: os.uname()的结果。
该对象可以作为(sysname, nodename, release, version, machine)的元组访问,
也可以通过属性sysname, nodename, release, version和machine访问。
参见:os.uname,获得更多信息。

data

1 machine= kind:data type:member_descriptor class:
2 n_fields=5 kind:data type:int class:
3 n_sequence_fields=5 kind:data type:int class:
4 n_unnamed_fields=0 kind:data type:int class:
5 nodename= kind:data type:member_descriptor class:
6 release= kind:data type:member_descriptor class:
7 sysname= kind:data type:member_descriptor class:
8 version= kind:data type:member_descriptor class:

76 os.terminal_size

terminal_size, os.terminal_size, module=os, line:-1 at os.py

(columns, lines)元组,用于保存终端窗口大小

data

1 columns= kind:data type:member_descriptor class:
2 lines= kind:data type:member_descriptor class:
3 n_fields=2 kind:data type:int class:
4 n_sequence_fields=2 kind:data type:int class:
5 n_unnamed_fields=0 kind:data type:int class:

77 nt.DirEntry

DirEntry, nt.DirEntry, module=nt

data

1 name= kind:data type:member_descriptor class:
2 path= kind:data type:member_descriptor class:

method

3 inode(self, *args, **kwargs)

kind=method class=DirEntry objtype=method_descriptor line:655 at …-1026899380\nt.py

返回该条目的inode;缓存每个条目。

4 is_dir(self, *args, **kwargs)

kind=method class=DirEntry objtype=method_descriptor line:659 at …-1026899380\nt.py

如果条目是目录,则返回True;缓存每个条目。

5 is_file(self, *args, **kwargs)

kind=method class=DirEntry objtype=method_descriptor line:663 at …-1026899380\nt.py

如果条目是一个文件,则返回True;缓存每个条目。

6 is_symlink(self, *args, **kwargs)

kind=method class=DirEntry objtype=method_descriptor line:667 at …-1026899380\nt.py

如果条目是符号链接则返回True;缓存每个条目。

7 stat(self, *args, **kwargs)

kind=method class=DirEntry objtype=method_descriptor line:671 at …-1026899380\nt.py

返回条目的统计结果对象;缓存每个条目。

78 collections.abc.MutableMapping

MutableMapping, collections.abc.MutableMapping, module=collections.abc, line:-1 at collections\abc.py

method

1 clear()

kind=method class=MutableMapping objtype=function

D.clear() -> None。从D中移除所有项目。

2 pop()

kind=method class=MutableMapping objtype=function

d .pop(k[,d]) -> v,删除指定键并返回相应值。如果没有找到key,则返回d,否则引发KeyError。

3 popitem()

kind=method class=MutableMapping objtype=function

D.popitem() -> (k, v),删除并返回一些(键,值)对作为2元组;但如果D为空则引发KeyError。

4 setdefault()

kind=method class=MutableMapping objtype=function

D.setdefault(k[,d]) -> D.get(k,d),如果k不在d中,也设置 D[k]=d

5 update()

kind=method class=MutableMapping objtype=function

D.update([E, ]**F) -> None。从mapping/iterable E和F更新D,
如果E存在并且有.keys()方法,则执行: for k in E: D[k] = E[k]
如果E存在并且没有.keys()方法,则执行: for (k, v) in E: D[k] = v
在任何一种情况下,都会执行: for k, v in F.items(): D[k] = v

79 os._Environ

_Environ, os._Environ, module=os, line:666 at os.py

method

1 copy(self)

kind=method class=_Environ objtype=function line:713 at …\lib\os.py

2 setdefault(self, key, value)

kind=method class=_Environ objtype=function line:716 at …\lib\os.py

80 os._wrap_close

_wrap_close, os._wrap_close, module=os, line:1002 at os.py

method

1 close(self)

kind=method class=_wrap_close objtype=function line:1006 at …\lib\os.py

81 os.PathLike

PathLike, os.PathLike, module=os, line:1070 at os.py

实现文件系统路径协议的抽象基类。

内嵌函数或方法

82	stat	
83	access	
84	chdir	
85	chmod	
86	getcwd	
87	getcwdb	
88	link	
89	listdir	
90	lstat	
91	mkdir	
92	readlink	
93	rename	
94	replace	
95	rmdir	
96	symlink	
97	system	
98	umask	
99	unlink	
100	remove	
101	utime	
102	times	
103	execv	
104	execve	
105	spawnv	
106	spawnve	
107	getpid	
108	getppid	
109	getlogin	
110	kill	
111	startfile	
112	waitpid	
113	open	
114	close	
115	closerange	
116	device_encoding	
117	dup	
118	dup2	
119	lseek	
120	read	
121	write	
122	fstat	
123	isatty	
124	pipe	
125	ftruncate	
126	truncate	
127	putenv	
128	strerror	
129	fsync	
130	abort	
131	urandom	
132	get_terminal_size	
133	cpu_count	
134	get_inheritable	
135	set_inheritable	
136	get_handle_inheritable	
137	set_handle_inheritable	
138	scandir	
139	fspath	
140	_exit	
141	_putenv	

私有或局部

142	_check_methods	
143	_exists	
144	_get_exports_list	
145	_exit	
146	_execvpe	
147	_Environ	
148	_putenv	
149	_unsetenv	 at 0x000000000281E558>
150	_wrap_close	
151	_fspath	

剩余

152	__loader__	<_frozen_importlib_external.SourceFileLoader object at 0x0000000002456CC8>
153	__spec__	ModuleSpec(name='os', loader=<_frozen_importlib_external.SourceFileLoader object at 0x0000000002456CC8>, origin='...\\lib\\os.py')
154	environ	environ({...})

统计

序号 类别 数量
2 bool 1
4 str 13
6 list 1
8 dict 1
9 module 4
11 function 30
12 builtin_function_or_method 4
13 residual 2
14 system 9
15 private 5
16 all 56

【ntpath】

ntpath, fullname=ntpath, file=ntpath.py

常见的路径名操作,WindowsNT/95版本。不要直接导入这个模块,而是导入os并将这个模块引用为os.path。

常量

bool

1 supports_unicode_filenames True

str

2 curdir .
3 pardir …
4 extsep .
5 sep
6 pathsep ;
7 altsep /
8 defpath .;C:\bin
9 devnull nul

模块

10 os

os, fullname=os, file=os.py

11 sys

sys, fullname=sys, file=

12 stat

stat, fullname=stat, file=stat.py

13 genericpath

genericpath, fullname=genericpath, file=genericpath.py

多个操作系统共用的路径操作请勿直接使用。特定于操作系统的模块导入相应的这个模块本身的函数。

函数

14 commonprefix(m)

commonprefix(m), module=genericpath, line:69 at genericpath.py

给定一个路径名列表,返回最长公共前导组件

15 exists(path)

exists(path), module=genericpath, line:16 at genericpath.py

测试路径是否存在。对于断开的符号链接返回False

16 getatime(filename)

getatime(filename), module=genericpath, line:58 at genericpath.py

返回文件的最后一次访问时间,由os.stat()报告。

17 getctime(filename)

getctime(filename), module=genericpath, line:63 at genericpath.py

返回由os.stat()报告的文件元数据更改时间。

18 getmtime(filename)

getmtime(filename), module=genericpath, line:53 at genericpath.py

返回文件的最后一次修改时间,由os.stat()报告。

19 getsize(filename)

getsize(filename), module=genericpath, line:48 at genericpath.py

返回文件的大小,由os.stat()报告。

20 isfile(path)

isfile(path), module=genericpath, line:27 at genericpath.py

测试路径是否为常规文件

21 samefile(f1, f2)

samefile(f1, f2), module=genericpath, line:94 at genericpath.py

测试两个路径名是否引用相同的实际文件或目录这由设备号和i-node号决定,如果对任意一个路径名的os.stat()调用失败将引发异常。

22 sameopenfile(fp1, fp2)

sameopenfile(fp1, fp2), module=genericpath, line:107 at genericpath.py

测试两个打开的文件对象是否引用同一个文件

23 samestat(s1, s2)

samestat(s1, s2), module=genericpath, line:87 at genericpath.py

测试两个统计缓冲区是否引用同一个文件

24 _get_bothseps(path)

_get_bothseps(path), module=ntpath, line:34 at ntpath.py

25 normcase(s)

normcase(s), module=ntpath, line:44 at ntpath.py

规范化路径名的大小写。使所有字符小写,所有斜杠为反斜杠。

26 isabs(s)

isabs(s), module=ntpath, line:67 at ntpath.py

测试路径是否为绝对路径

27 join(path, *paths)

join(path, *paths), module=ntpath, line:75 at ntpath.py

28 splitdrive§

splitdrive§, module=ntpath, line:122 at ntpath.py

将路径名拆分为驱动器/UNC共享点和相对路径说明符。
返回一个二元组(drive_or_unc, path);任何一部分都可能是空的。
如果你分配
result = splitdrive(p),
它总是正确的:
result[0] + result[1] = p
如果路径包含驱动器号,drive_or_unc 将包含冒号之前的所有内容。
例如:splitdrive("c:/dir") 返回 ("c:", "/dir")
如果路径包含UNC路径,则驱动器或UNC将包含主机名并共享到但不包括第四个目录分隔符字符。
例如:splitdrive("//host/computer/dir") 返回 ("//host/computer", "/dir")
路径不能同时包含盘符和UNC路径。

29 split§

split§, module=ntpath, line:178 at ntpath.py

拆分路径名。返回元组(head, tail),其中tail是最后一个斜杠之后的所有内容。任何一部分都可能是空的。

30 splitext§

splitext§, module=ntpath, line:201 at ntpath.py

从路径名中分离扩展名。扩展是从最后一个点到最后一个点,忽略前面的点。返回"(root, ext)";Ext可能为空。

31 basename§

basename§, module=ntpath, line:212 at ntpath.py

返回路径名的最后一个组件

32 dirname§

dirname§, module=ntpath, line:219 at ntpath.py

返回路径名的目录组件

33 islink(path)

islink(path), module=ntpath, line:226 at ntpath.py

测试路径是否为符号链接。对于6.0之前的Windows,这将总是返回false。

34 lexists(path)

lexists(path), module=ntpath, line:238 at ntpath.py

测试路径是否存在。对于损坏的符号链接返回True

35 ismount(path)

ismount(path), module=ntpath, line:260 at ntpath.py

测试路径是否是一个挂载点(驱动器根、共享根或挂载的卷)

36 expanduser(path)

expanduser(path), module=ntpath, line:287 at ntpath.py

展开~和~user构造。如果user或$HOME未知,什么都不做。

37 expandvars(path)

expandvars(path), module=ntpath, line:337 at ntpath.py

展开窗体$var, ${var}和%var%的shell变量。未知变量保持不变。

38 normpath(path)

normpath(path), module=ntpath, line:450 at ntpath.py

正常化路径,消除双斜杠等。

39 _abspath_fallback(path)

_abspath_fallback(path), module=ntpath, line:499 at ntpath.py

在`nt._getfullpathname`不可用或引发OSError情况下,返回路径的绝对版本作为回退函数。
参见bpo-31047 了解更多。

40 abspath(path)

abspath(path), module=ntpath, line:523 at ntpath.py

返回路径的绝对版本。

41 abspath(path)

abspath(path), module=ntpath, line:523 at ntpath.py

返回路径的绝对版本。

42 relpath(path, start=None)

relpath(path, start=None), module=ntpath, line:536 at ntpath.py

返回路径的相对版本

43 commonpath(paths)

commonpath(paths), module=ntpath, line:592 at ntpath.py

给定一个路径名称序列,返回最长公共子路径。

内嵌函数或方法

44	isdir	
45	_getvolumepathname	
46	_getfullpathname	
47	_getfinalpathname	

私有或局部

48	_get_bothseps	
49	_getvolumepathname	
50	_abspath_fallback	
51	_getfullpathname	
52	_getfinalpathname	

【sys】

sys, fullname=sys, file=

参见:sys 模块

【stat】

stat, fullname=stat, file=stat.py

用于解释os.stat()和os.lstat()结果的常量/函数。建议使用:from stat import *

常量

int

1	ST_MODE	0
2	ST_INO	1
3	ST_DEV	2
4	ST_NLINK	3
5	ST_UID	4
6	ST_GID	5
7	ST_SIZE	6
8	ST_ATIME	7
9	ST_MTIME	8
10	ST_CTIME	9
11	S_IFDIR	16384
12	S_IFCHR	8192
13	S_IFBLK	24576
14	S_IFREG	32768
15	S_IFIFO	4096
16	S_IFLNK	40960
17	S_IFSOCK	49152
18	S_IFDOOR	0
19	S_IFPORT	0
20	S_IFWHT	0
21	S_ISUID	2048
22	S_ISGID	1024
23	S_ENFMT	1024
24	S_ISVTX	512
25	S_IREAD	256
26	S_IWRITE	128
27	S_IEXEC	64
28	S_IRWXU	448
29	S_IRUSR	256
30	S_IWUSR	128
31	S_IXUSR	64
32	S_IRWXG	56
33	S_IRGRP	32
34	S_IWGRP	16
35	S_IXGRP	8
36	S_IRWXO	7
37	S_IROTH	4
38	S_IWOTH	2
39	S_IXOTH	1
40	UF_NODUMP	1
41	UF_IMMUTABLE	2
42	UF_APPEND	4
43	UF_OPAQUE	8
44	UF_NOUNLINK	16
45	UF_COMPRESSED	32
46	UF_HIDDEN	32768
47	SF_ARCHIVED	65536
48	SF_IMMUTABLE	131072
49	SF_APPEND	262144
50	SF_NOUNLINK	1048576
51	SF_SNAPSHOT	2097152
52	FILE_ATTRIBUTE_ARCHIVE	32
53	FILE_ATTRIBUTE_COMPRESSED	2048
54	FILE_ATTRIBUTE_DEVICE	64
55	FILE_ATTRIBUTE_DIRECTORY	16
56	FILE_ATTRIBUTE_ENCRYPTED	16384
57	FILE_ATTRIBUTE_HIDDEN	2
58	FILE_ATTRIBUTE_INTEGRITY_STREAM	32768
59	FILE_ATTRIBUTE_NORMAL	128
60	FILE_ATTRIBUTE_NOT_CONTENT_INDEXED	8192
61	FILE_ATTRIBUTE_NO_SCRUB_DATA	131072
62	FILE_ATTRIBUTE_OFFLINE	4096
63	FILE_ATTRIBUTE_READONLY	1
64	FILE_ATTRIBUTE_REPARSE_POINT	1024
65	FILE_ATTRIBUTE_SPARSE_FILE	512
66	FILE_ATTRIBUTE_SYSTEM	4
67	FILE_ATTRIBUTE_TEMPORARY	256
68	FILE_ATTRIBUTE_VIRTUAL	65536

tuple

69 _filemode_table (((40960, ‘l’), (32768, ‘-’), (24576, ‘b’), (16384, ‘d’), (8192, ‘c’), (4096, 'p…

内嵌函数或方法

70	S_IMODE	
71	S_IFMT	
72	S_ISDIR	
73	S_ISCHR	
74	S_ISBLK	
75	S_ISREG	
76	S_ISFIFO	
77	S_ISLNK	
78	S_ISSOCK	
79	S_ISDOOR	
80	S_ISPORT	
81	S_ISWHT	
82	filemode	

私有或局部

83 _filemode_table (((40960, ‘l’), (32768, ‘-’), (24576, ‘b’), (16384, ‘d’), (8192, ‘c’), (4096, 'p…

统计

序号 类别 数量
4 str 5
6 list 1
8 dict 1
9 module 2
11 function 13
13 residual 2
14 system 9
15 private 2
16 all 24

【genericpath】

genericpath, fullname=genericpath, file=genericpath.py

多个操作系统共用的路径操作请勿直接使用。特定于操作系统的模块从该模块本身导入适当的函数。

模块

1 os

os, fullname=os, file=os.py

参见: os 模块

2 stat

stat, fullname=stat, file=stat.py

参见: stat 模块

函数

3 exists(path)

exists(path), module=genericpath, line:16 at genericpath.py

测试路径是否存在。对于断开的符号链接返回False

4 isfile(path)

isfile(path), module=genericpath, line:27 at genericpath.py

测试路径是否为常规文件

5 isdir(s)

isdir(s), module=genericpath, line:39 at genericpath.py

如果路径名指向现有目录,则返回true。

6 getsize(filename)

getsize(filename), module=genericpath, line:48 at genericpath.py

返回文件的大小,由os.stat()报告。

7 getmtime(filename)

getmtime(filename), module=genericpath, line:53 at genericpath.py

返回文件的最后一次修改时间,由os.stat()报告。

8 getatime(filename)

getatime(filename), module=genericpath, line:58 at genericpath.py

返回文件的最后一次访问时间,由os.stat()报告。

9 getctime(filename)

getctime(filename), module=genericpath, line:63 at genericpath.py

返回由os.stat()报告的文件元数据更改时间。

10 commonprefix(m)

commonprefix(m), module=genericpath, line:69 at genericpath.py

给定一个路径名列表,返回最长公共前导组件

11 samestat(s1, s2)

samestat(s1, s2), module=genericpath, line:87 at genericpath.py

测试两个统计缓冲区是否引用同一个文件

12 samefile(f1, f2)

samefile(f1, f2), module=genericpath, line:94 at genericpath.py

测试两个路径名是否引用相同的实际文件或目录这由设备号和i-node号决定,如果对任意一个路径名的os.stat()调用失败将引发异常。

13 sameopenfile(fp1, fp2)

sameopenfile(fp1, fp2), module=genericpath, line:107 at genericpath.py

测试两个打开的文件对象是否引用同一个文件

14 _splitext(p, sep, altsep, extsep)

_splitext(p, sep, altsep, extsep), module=genericpath, line:121 at genericpath.py

从路径名中分离扩展名。扩展是从最后一个点到最后一个点,忽略前面的点。返回"(root, ext)";Ext可能为空。

15 _check_arg_types(funcname, *args)

_check_arg_types(funcname, *args), module=genericpath, line:144 at genericpath.py

私有或局部

16 _splitext
17 _check_arg_types

你可能感兴趣的:(菜鸟学python,python,开发语言)