python之常用标准库-sys/os

Wait for bloom / 2024-01-29 / 原文

1.sys

sys常用的方法sys.path.append/sys.path.insert

1 #!/usr/bin/python
2 import os,sys
3 sys.path.insert(0,os.path.dirname(os.path.dirname(__file__))) #将路径插入第1个位置
4 sys.path.append(os.path.dirname(os.path.dirname(__file__)))#将路径追加到末尾
View Code

2.os

目前主要用来添加路径,后续再补充其他

1 #!/usr/bin/python
2 import os,sys
3 print(os.path.dirname(__file__))
4 print(os.path.dirname(os.path.dirname(__file__)))
View Code