执行shell命令
1.supprocess
2.commands
# -*- coding:utf-8 -*- import subprocess import commands # py3/py2 result = subprocess.check_output('dir',cwd='D:m1day07') print(result) # py2 result = commands.getoutput('dir') print(result)
压缩和解压文件
import shutil
#压缩用shutil # py2/py3 # shutil.make_archive(r'D:m1day07x1',format='zip',root_dir='D:m1day07m1') # py3 # shutil._unpack
#解压用zipfile或tarfile # py2/py3 import zipfile import tarfile obj = zipfile.ZipFile(r'D:m1day07x1.zip',mode='r') obj.extractall(r'D:m1day07files') obj.close()
查看目录下所有文件
import os #os.listdir只能显示一层目录 # for li in os.listdir(r'D:m1day07files'): # print(li) #os.walk能显示所有的文件. # for base,folder,files in os.walk(r'D:m1day07files'): # for item in files: # file_path = os.path.join(base,item) # print(file_path)
根据pid杀死进程
# -*- coding:utf-8 -*- import os import signal os.kill(1223,signal.SIGBREAK) #signal.SIGBREAK可以用9这个数字替换