一:os模块分类:
二:os模块大全表
序号 | 方法 | 方法 |
1 | 检验权限模式 | |
2 | ||
3 | ||
4 | ||
5 | ||
6 | ||
7 | ||
8 | ||
9 | ||
10 | ||
11 | ||
12 | ||
13 | ||
14 | ||
15 | ||
16 | ||
17 | ||
18 | ||
19 | ||
20 | ||
21 | ||
22 | ||
23 | ||
24 | ||
25 | ||
26 | ||
27 | ||
28 | ||
29 | ||
30 | ||
31 | ||
32 | ||
33 | ||
34 | ||
35 | ||
36 | ||
37 | ||
38 | ||
39 | ||
40 | ||
41 | ||
42 | ||
43 | ||
44 | ||
45 | ||
46 | ||
47 | ||
48 | ||
49 | ||
50 | ||
51 | ||
52 | ||
53 | ||
54 | ||
55 | ||
56 | ||
57 | ||
58 | ||
59 | ||
60 | ||
61 | ||
62 | ||
63 | ||
64 |
三:os.path.abspath和os.path.dirname()
1)在pycharm内执行代码,获取执行文件的路径或者目录print(__file__)-------------结果:C:/mcw/mcwtest_dir/mcw1.pyimport osprint(os.path.dirname(__file__))----------结果:C:/mcw/mcwtest_dirimport osprint(os.path.dirname(os.path.dirname(__file__)))----------结果;C:/mcw2)在命令行只能获取到相对路径import osprint(__file__)-----------------结果:(venv) C:\mcw\mcwtest_dir>python3 mcw1.pymcw1.pyimport osprint(os.path.dirname(__file__))import osprint(os.path.dirname(os.path.dirname(__file__)))------------------------结果:(venv) C:\mcw\mcwtest_dir>python3 c:/mcw/mcwtest_dir/mcw1.pyc:/mcw3)使用abspath()就可以在命令行获取执行文件的绝对路径import osprint(os.path.dirname(os.path.abspath(__file__)))----------------------结果:(venv) C:\mcw\mcwtest_dir>python3 mcw1.pyC:\mcw\mcwtest_dir
参考链接:
1)https://www.runoob.com/python/os-file-methods.html