标签:environ ppi 移植 linux系统 dirname pre strong 存在 py3
sys:提供一组功能映射Python运行时的操作系统
sys.platform
'win32'
sys.version
'3.6.2 (v3.6.2:5fd33b5, Jul 8 2017, 04:57:36) [MSC v.1900 64 bit (AMD64)]'
sys.path
['D:\\mysoftware\\PyCharm 2019.1.3\\helpers\\pydev', 'D:\\mysoftware\\PyCharm 2019.1.3\\helpers\\pycharm_display', 'D:\\mysoftware\\PyCharm 2019.1.3\\helpers\\third_party\\thriftpy', 'D:\\mysoftware\\PyCharm 2019.1.3\\helpers\\pydev', 'E:\\py\\PY_demo1\\venv\\Scripts\\python36.zip', 'D:\\mysoftware\\Python36\\DLLs', 'D:\\mysoftware\\Python36\\lib', 'D:\\mysoftware\\Python36', 'E:\\py\\PY_demo1\\venv', 'E:\\py\\PY_demo1\\venv\\lib\\site-packages', 'E:\\py\\PY_demo1\\venv\\lib\\site-packages\\setuptools-40.8.0-py3.6.egg', 'E:\\py\\PY_demo1\\venv\\lib\\site-packages\\pip-19.0.3-py3.6.egg', 'D:\\mysoftware\\PyCharm 2019.1.3\\helpers\\pycharm_matplotlib_backend', 'E:\\py\\PY_demo1', 'E:/py/PY_demo1']
---------------------------------------------------
sys.modules#程序当前载入的模块
import traceback
try:
raise KeyError
except:
print(sys.exc_info())
(<class 'KeyError'>, KeyError(), <traceback object at 0x0000014B029D6448>)
----------------------------------------------------------------------------
try:
raise KeyError
except:
print(sys.exc_info())
traceback.print_tb(sys.exc_info()[2])
(<class 'KeyError'>, KeyError(), <traceback object at 0x0000014B02A3A4C8>)
File "<input>", line 2, in <module>
sys.argv
命令行运行时的所有参数列表
标准流
sys.stdin()
sys.stdout()
sys.stderror()
os:提供跨平台可移植的操作系统编程接口
os.getcwd()
'E:\\py\\PY_demo1'
----------------------
os.listdir()
['.idea', 'a', 'a.txt', 'assert_method.py', 'coder.py', 'data.txt', 'date_list.txt', 'example.py', 'except.py', 'flat_file.py', 'fun_demo.py', 'lambd.py', 'main.py', 'Main2.py', 'package_demo.py', 'shelvedemo.py', 'shelve_student.bak', 'shelve_student.dat', 'shelve_student.dir', 'Test.py', 'Test2.py', 'test_coder.py', 'unitest.py', 'venv', '__pycache__']
----------------------------------
os.chdir(a)
--------------------------
os.getpid()
23028
os.getppid()
8000
os.system('dir /a') #windows系统
os.system('ls /a') #linux系统
---------------------------------------------
f = os.popen('dir /a').read()
f = os.popen('dir /a').readlines()
os.rename('a.txt','b.txt')
os.remove('b.txt')
os.mkdir('a')
os.rmdir('a')
os.sep #当前操作系统的分隔符
os.pathsep #路径分隔符,多个路径的分隔
os.curdir #.
os.pardir #..
os.path.isdir() #判断是否为dir
os.path.isfile() #是否为文件
os.path.exists() #是否存在
os.path.getsize() #多少字节
--------------------------------
os.path.split(r'c:\data\q.txt')
('c:\\data', 'q.txt')
name.split(os.sep)
['c:', 'data', 'q.txt']
--------------------------------
os.path.dirname(name)
'c:\\data'
os.path.basename(name)
'q.txt'
--------------------------------
os.path.splitext(name)
('c:\\data\\q', '.txt')
--------------------------------
os.path.join(r'c:\remp','a.txt')
'c:\\remp\\a.txt'
-------------------------------
p = 'd:\\app\\db/file/data.txt'
os.path.normpath(p) #规范标准化路径
'd:\\app\\db\\file\\data.txt'
-----------------------------------
os.path.abspath('..')
'E:\\py'
标签:environ ppi 移植 linux系统 dirname pre strong 存在 py3
原文地址:https://www.cnblogs.com/gdy1993/p/12173759.html