Python--常用第三方模块
Python常用第三方模块
Windows用管理员打开py shell
1.Pillow
安装Pillow
pip install pillow
缩放图片
from PIL import Image im = Image.open('test.jpg') w, h = im.size im.thumbnail((w//2, h//2)) im.save('thumbnail.jpg', 'jpeg')
模糊图片
from PIL import Image, ImageFilter im = Image.open('test.jpg') im2 = im.filter(ImageFilter.BLUR) Im2.save('blur.jpg', 'jpeg')
绘制验证码
from PIL import Image, ImageDraw, ImageFont, ImageFilter import random def randChar(): return chr(random.randint(65,90)) def randColor(): return (random.randint(64, 255), random.randint(64, 255), random.randint(64, 255)) def randColor2(): return (random.randint(32, 127), random.randint(32, 127), random.randint(32, 127)) width = 60 *4 height = 60 image = Image.new('RGB', (width, height), (255, 255, 255)) font = ImageFont.truetype('c://windows/fonts/Arial.ttf', 36) draw = ImageDraw.Draw(image) for x in range(width): for y in range(height): draw.point((x, y), fill=rndColor()) for t in range(4): draw.text((60 * t + 10, 10), rndChar(), font=font, fill=rndColor2()) image = image.filter(ImageFilter.BLUR) image.save('code.jpg', 'jpeg')
2.request
安装request
pip install request
使用request
通过GET访问一个页面,只需要几行代码:
import requests r = requests.get('https://www.baidu.com/') r.status_code r.text
对于带参数的URL,传入一个dict作为parameter参数
留坑。。。
3.chardet
与字符串编码相关
安装chardet
pip install chardet
使用chardet
检测编码 chardet.detect(b'Hello, world!')
data = '离离原上草,一岁一枯荣'.encode('gbk') chardet.detect(data) data = '离离原上草,一岁一枯荣'.encode('utf-8') chardet.detect(data) data = '最新の主要ニュース'.encode('euc-jp') chardet.detect(data)
4.psutil
安装psutil
pip install psutil
使用pustil
>>> import psutil >>> psutil.cpu_count()#cpu逻辑数 4 >>> psutil.cpu_count(logical=False)#cpu物理核心 2 >>> psutil.cpu_times()#统计cpu使用时间 scputimes(user=2939.28125, system=4654.390625, idle=122091.515625, interrupt=376.046875, dpc=214.59375) #统计cpu使用率,每秒刷新一次,累计十次 >>> for x in range(10): psutil.cpu_percent(interval=1, percpu=True) [0.0, 1.6, 6.2, 1.6] [0.0, 0.0, 3.1, 0.0] [1.6, 0.0, 3.1, 0.0] [0.0, 0.0, 0.0, 1.6] [0.0, 0.0, 1.6, 1.6] [0.0, 1.6, 1.6, 1.6] [1.6, 0.0, 0.0, 0.0] [0.0, 3.1, 1.6, 0.0] [0.0, 1.6, 1.6, 0.0] [1.6, 0.0, 1.6, 0.0] >>> psutil.virtual_memory()#物理内存,//我也不知道为甚是virtual memory svmem(total=8473534464, available=3817754624, percent=54.9, used=4655779840, free=3817754624) >>> psutil.swap_memory()#交换区大小 sswap(total=17063469056, used=6417596416, free=10645872640, percent=37.6, sin=0, sout=0) >>> psutil.disk_partitions()#分区情况 [sdiskpart(device='C:\\', mountpoint='C:\\', fstype='NTFS', opts='rw,fixed'), sdiskpart(device='D:\\', mountpoint='D:\\', fstype='NTFS', opts='rw,fixed'), sdiskpart(device='E:\\', mountpoint='E:\\', fstype='NTFS', opts='rw,fixed'), sdiskpart(device='F:\\', mountpoint='F:\\', fstype='NTFS', opts='rw,fixed'), sdiskpart(device='G:\\', mountpoint='G:\\', fstype='', opts='cdrom'), sdiskpart(device='H:\\', mountpoint='H:\\', fstype='NTFS', opts='rw,fixed'), sdiskpart(device='I:\\', mountpoint='I:\\', fstype='NTFS', opts='rw,fixed'), sdiskpart(device='J:\\', mountpoint='J:\\', fstype='NTFS', opts='rw,fixed')] >>> psutil.disk_usage('/')#磁盘'/',即所有磁盘的使用情况 sdiskusage(total=237943910400, used=187740995584, free=50202914816, percent=78.9) >>> psutil.disk_io_counters()#磁盘IO sdiskio(read_count=320445, write_count=354067, read_bytes=9422442496, write_bytes=7091268608, read_time=2584, write_time=376) >>> psutil.net_io_counters()#获取网络读写字节/包的个数 snetio(bytes_sent=8183238, bytes_recv=13062856, packets_sent=21267, packets_recv=22614, errin=0, errout=0, dropin=0, dropout=0) >>> psutil.net_if_addrs()#获取网络接口信息 {'本地连接* 1': [snicaddr(family=<AddressFamily.AF_LINK: -1>, address='12-A5-89-78-9A-9D', netmask=None, broadcast=None, ptp=None), snicaddr(family=<AddressFamily.AF_INET: 2>, address='169.254.154.0', netmask='255.255.0.0', broadcast=None, ptp=None), snicaddr(family=<AddressFamily.AF_INET6: 23>, address='fe80::551e:cb09:361d:9a00', netmask=None, broadcast=None, ptp=None)], '以太网 4': [snicaddr(family=<AddressFamily.AF_LINK: -1>, address='00-FF-AC-4C-D5-93', netmask=None, broadcast=None, ptp=None), snicaddr(family=<AddressFamily.AF_INET: 2>, address='169.254.58.234', netmask='255.255.0.0', broadcast=None, ptp=None), snicaddr(family=<AddressFamily.AF_INET6: 23>, address='fe80::38ea:8483:4a09:3aea', netmask=None, broadcast=None, ptp=None)], 'WLAN': [snicaddr(family=<AddressFamily.AF_LINK: -1>, address='80-A5-89-78-9A-9D', netmask=None, broadcast=None, ptp=None), snicaddr(family=<AddressFamily.AF_INET: 2>, address='192.168.43.63', netmask='255.255.255.0', broadcast=None, ptp=None), snicaddr(family=<AddressFamily.AF_INET6: 23>, address='2408:84f2:548:4d9e:f470:aa5b:d7f4:3e1a', netmask=None, broadcast=None, ptp=None), snicaddr(family=<AddressFamily.AF_INET6: 23>, address='2408:84f2:548:4d9e:21cb:d45b:b97d:1569', netmask=None, broadcast=None, ptp=None), snicaddr(family=<AddressFamily.AF_INET6: 23>, address='fe80::f470:aa5b:d7f4:3e1a', netmask=None, broadcast=None, ptp=None)], '本地连接* 2': [snicaddr(family=<AddressFamily.AF_LINK: -1>, address='22-A5-89-78-9A-9D', netmask=None, broadcast=None, ptp=None), snicaddr(family=<AddressFamily.AF_INET: 2>, address='192.168.137.1', netmask='255.255.255.0', broadcast=None, ptp=None), snicaddr(family=<AddressFamily.AF_INET6: 23>, address='fe80::61c3:c013:7122:2152', netmask=None, broadcast=None, ptp=None)], '蓝牙网络连接 2': [snicaddr(family=<AddressFamily.AF_LINK: -1>, address='80-A5-89-78-9A-9C', netmask=None, broadcast=None, ptp=None), snicaddr(family=<AddressFamily.AF_INET: 2>, address='169.254.178.119', netmask='255.255.0.0', broadcast=None, ptp=None), snicaddr(family=<AddressFamily.AF_INET6: 23>, address='fe80::744a:d6e7:4ef:b277', netmask=None, broadcast=None, ptp=None)], 'Loopback Pseudo-Interface 1': [snicaddr(family=<AddressFamily.AF_INET: 2>, address='127.0.0.1', netmask='255.0.0.0', broadcast=None, ptp=None), snicaddr(family=<AddressFamily.AF_INET6: 23>, address='::1', netmask=None, broadcast=None, ptp=None)]} >>> psutil.net_if_stats()#获取网络接口状态 {'蓝牙网络连接 2': snicstats(isup=False, duplex=<NicDuplex.NIC_DUPLEX_FULL: 2>, speed=3, mtu=1500), '以太网 4': snicstats(isup=False, duplex=<NicDuplex.NIC_DUPLEX_FULL: 2>, speed=10, mtu=1400), 'Loopback Pseudo-Interface 1': snicstats(isup=True, duplex=<NicDuplex.NIC_DUPLEX_FULL: 2>, speed=1073, mtu=1500), 'WLAN': snicstats(isup=True, duplex=<NicDuplex.NIC_DUPLEX_FULL: 2>, speed=108, mtu=1500), '本地连接* 1': snicstats(isup=False, duplex=<NicDuplex.NIC_DUPLEX_FULL: 2>, speed=0, mtu=1500), '本地连接* 2': snicstats(isup=True, duplex=<NicDuplex.NIC_DUPLEX_FULL: 2>, speed=108, mtu=1500)} >>> psutil.net_connections()#获取当前网络连接信息,不知道为啥我的有几百行信息,可能是虚拟机比较多 *****太多了 >>> psutil.pids()#所有进程的ID [0, 4, 96, 224, 356, 440, 464, 592, 700, 772, 784, 876, 892, 916, 940, 1196, 1236, 1244, 1248, 1260, 1268, 1436, 1488, 1500, 1544, 1552, 1556, 1652, 1696, 1768, 1808, 1824, 1848, 1976, 1984, 2032, 2060, 2068, 2088, 2188, 2200, 2232, 2276, 2308, 2440, 2460, 2480, 2560, 2568, 2600, 2608, 2620, 2664, 2700, 2720, 2792, 2852, 2968, 2976, 3180, 3192, 3208, 3232, 3248, 3300, 3328, 3348, 3352, 3392, 3532, 3552, 3572, 3648, 3652, 3728, 3760, 3780, 3832, 3844, 3872, 3968, 3980, 3988, 4012, 4048, 4056, 4184, 4208, 4232, 4268, 4316, 4348, 4356, 4408, 4452, 4464, 4484, 4516, 4532, 4568, 4580, 4624, 4636, 4684, 4692, 4700, 4724, 4736, 4744, 4792, 4924, 5132, 5156, 5176, 5264, 5280, 5468, 5476, 5544, 5716, 6088, 6112, 6140, 6228, 6376, 6432, 6488, 6796, 6848, 7148, 7336, 7460, 7544, 7708, 7732, 7740, 7764, 7796, 7944, 7968, 8020, 8152, 8288, 8632, 8644, 8656, 8828, 8904, 8908, 8928, 8968, 9036, 9096, 9196, 9220, 9320, 9548, 9620, 9676, 9684, 9852, 9908, 9992, 10112, 10176, 10184, 10208, 10392, 10424, 10428, 10488, 10492, 10584, 10628, 10888, 11000, 11012, 11028, 11040, 11196, 11324, 11384, 11416, 11532, 11624, 11884, 11944, 11952, 12132, 12188, 12320, 12348, 12456, 12464, 12676, 12724, 12756, 12800, 12872, 12904, 13000, 13008, 13028, 13304, 13580, 13648, 13720, 14048, 14076, 14084, 14192, 14256, 14284, 14348, 14640] >>> p = psutil.Process(3352)#获取指定进程ID=3352 ,360 >>> p.name()#进程p的名字 '360tray.exe' >>> p.exe()#进程p的.exe路径 'D:\\Program Files (x86)\\360\\360safe\\safemon\\360tray.exe' >>> p.cwd()#进程p的工作目录 'D:\\Program Files (x86)\\360\\360safe\\Config\\newui\\themes\\default' >>> p.cmdline()#进程p的启动命令 ['D:\\Program Files (x86)\\360\\360safe\\safemon\\360tray.exe', '/start'] >>> p.ppid()#进程p的父进程ID 3328 >>> p.parent()#进程P的父进程 psutil.Process(pid=3328, name='ZhuDongFangYu.exe', started='2020-02-06 18:05:25') >>> p.children()#进程p的子进程 [] >>> p.status()#进程p的状态 'running' >>> p.username()#进程p的用户名字 'DESKTOP-TQ6HH1U\\YJEthan' >>> p.create_time()#进程p的创建时间 1581048910.0 >>> p.terminal()#进程终端,也许windows OS上不支持该命令 Traceback (most recent call last): File "<pyshell#92>", line 1, in <module> p.terminal() AttributeError: 'Process' object has no attribute 'terminal' >>> p.cpu_times()#进程p使用CPU的时间 pcputimes(user=71.671875, system=68.640625, children_user=0.0, children_system=0.0) >>> p.memory_info()#进程p的内存使用情况 pmem(rss=41803776, vms=220246016, num_page_faults=2280053, peak_wset=161460224, wset=41803776, peak_paged_pool=655336, paged_pool=618424, peak_nonpaged_pool=209128, nonpaged_pool=202144, pagefile=220246016, peak_pagefile=306270208, private=220246016) >>> p.open_files()#进程p打开的文件 [] >>> p.connections()#进程p建立的连接 [pconn(fd=-1, family=<AddressFamily.AF_INET: 2>, type=<SocketKind.SOCK_DGRAM: 2>, laddr=addr(ip='0.0.0.0', port=52203), raddr=(), status='NONE'), pconn(fd=-1, family=<AddressFamily.AF_INET: 2>, type=<SocketKind.SOCK_DGRAM: 2>, laddr=addr(ip='0.0.0.0', port=62132), raddr=(), status='NONE'), pconn(fd=-1, family=<AddressFamily.AF_INET: 2>, type=<SocketKind.SOCK_DGRAM: 2>, laddr=addr(ip='0.0.0.0', port=61893), raddr=(), status='NONE'), pconn(fd=-1, family=<AddressFamily.AF_INET: 2>, type=<SocketKind.SOCK_DGRAM: 2>, laddr=addr(ip='0.0.0.0', port=62178), raddr=(), status='NONE'), pconn(fd=-1, family=<AddressFamily.AF_INET: 2>, type=<SocketKind.SOCK_DGRAM: 2>, laddr=addr(ip='0.0.0.0', port=63392), raddr=(), status='NONE'), pconn(fd=-1, family=<AddressFamily.AF_INET: 2>, type=<SocketKind.SOCK_DGRAM: 2>, laddr=addr(ip='0.0.0.0', port=60789), raddr=(), status='NONE'), pconn(fd=-1, family=<AddressFamily.AF_INET: 2>, type=<SocketKind.SOCK_DGRAM: 2>, laddr=addr(ip='0.0.0.0', port=53754), raddr=(), status='NONE'), pconn(fd=-1, family=<AddressFamily.AF_INET: 2>, type=<SocketKind.SOCK_DGRAM: 2>, laddr=addr(ip='0.0.0.0', port=56592), raddr=(), status='NONE'), pconn(fd=-1, family=<AddressFamily.AF_INET: 2>, type=<SocketKind.SOCK_DGRAM: 2>, laddr=addr(ip='0.0.0.0', port=59483), raddr=(), status='NONE'), pconn(fd=-1, family=<AddressFamily.AF_INET: 2>, type=<SocketKind.SOCK_DGRAM: 2>, laddr=addr(ip='0.0.0.0', port=61264), raddr=(), status='NONE'), pconn(fd=-1, family=<AddressFamily.AF_INET: 2>, type=<SocketKind.SOCK_STREAM: 1>, laddr=addr(ip='192.168.43.63', port=57668), raddr=addr(ip='36.99.30.200', port=80), status='ESTABLISHED'), pconn(fd=-1, family=<AddressFamily.AF_INET: 2>, type=<SocketKind.SOCK_DGRAM: 2>, laddr=addr(ip='0.0.0.0', port=62131), raddr=(), status='NONE'), pconn(fd=-1, family=<AddressFamily.AF_INET: 2>, type=<SocketKind.SOCK_DGRAM: 2>, laddr=addr(ip='0.0.0.0', port=61363), raddr=(), status='NONE'), pconn(fd=-1, family=<AddressFamily.AF_INET: 2>, type=<SocketKind.SOCK_DGRAM: 2>, laddr=addr(ip='0.0.0.0', port=3600), raddr=(), status='NONE'), pconn(fd=-1, family=<AddressFamily.AF_INET: 2>, type=<SocketKind.SOCK_STREAM: 1>, laddr=addr(ip='192.168.43.63', port=57797), raddr=addr(ip='223.167.166.49', port=443), status='ESTABLISHED')] >>> p.num_threads()#进程p的子进程数目 141 >>> p.threads()#进程p的所有子进程 [pthread(id=3368, user_time=4.96875, system_time=4.984375), pthread(id=4212, user_time=0.0, system_time=0.0), pthread(id=10464, user_time=0.0, system_time=0.0), pthread(id=10044, user_time=0.5, system_time=1.71875), pthread(id=8572, user_time=0.0, system_time=0.0), pthread(id=5588, user_time=0.0, system_time=0.015625), pthread(id=10804, user_time=0.0, system_time=0.0), pthread(id=12156, user_time=0.015625, system_time=0.0), pthread(id=7960, user_time=0.078125, system_time=0.234375), pthread(id=3168, user_time=0.0625, system_time=0.09375), pthread(id=11872, user_time=0.046875, system_time=0.109375), pthread(id=7316, user_time=0.046875, system_time=0.03125), pthread(id=68, user_time=0.796875, system_time=0.15625), pthread(id=520, user_time=2.609375, system_time=3.265625), pthread(id=10364, user_time=7.125, system_time=6.96875), pthread(id=2424, user_time=0.0, system_time=0.0), pthread(id=3000, user_time=13.515625, system_time=14.46875), pthread(id=12956, user_time=0.171875, system_time=0.203125), pthread(id=9564, user_time=0.015625, system_time=0.015625), pthread(id=8064, user_time=0.0, system_time=0.0), pthread(id=12920, user_time=0.0, system_time=0.140625), pthread(id=6580, user_time=0.0, system_time=0.0), pthread(id=5876, user_time=0.0, system_time=0.0), pthread(id=536, user_time=0.390625, system_time=0.21875), pthread(id=11488, user_time=0.0, system_time=0.0), pthread(id=11068, user_time=0.0, system_time=0.0), pthread(id=12200, user_time=0.0, system_time=0.0), pthread(id=8960, user_time=0.0, system_time=0.0), pthread(id=8404, user_time=0.0, system_time=0.0), pthread(id=288, user_time=0.3125, system_time=2.21875), pthread(id=10976, user_time=0.5625, system_time=0.296875), pthread(id=3124, user_time=0.0, system_time=0.015625), pthread(id=1956, user_time=0.0, system_time=0.0), pthread(id=12868, user_time=0.0, system_time=0.0), pthread(id=1336, user_time=0.0, system_time=0.0), pthread(id=11476, user_time=0.0, system_time=0.015625), pthread(id=12500, user_time=0.0, system_time=0.0), pthread(id=3204, user_time=0.015625, system_time=0.03125), pthread(id=6024, user_time=0.0, system_time=0.0), pthread(id=12648, user_time=0.0625, system_time=0.484375), pthread(id=1388, user_time=0.0, system_time=0.0), pthread(id=7880, user_time=0.09375, system_time=0.265625), pthread(id=2368, user_time=0.015625, system_time=0.0), pthread(id=8504, user_time=0.0, system_time=0.0), pthread(id=4304, user_time=0.03125, system_time=0.125), pthread(id=8988, user_time=0.03125, system_time=0.015625), pthread(id=9544, user_time=1.328125, system_time=2.78125), pthread(id=4500, user_time=0.75, system_time=1.078125), pthread(id=5836, user_time=0.03125, system_time=0.015625), pthread(id=10232, user_time=0.25, system_time=0.53125), pthread(id=12040, user_time=1.515625, system_time=1.0625), pthread(id=10092, user_time=0.0, system_time=0.0), pthread(id=10136, user_time=0.0, system_time=0.0), pthread(id=13284, user_time=0.0, system_time=0.0), pthread(id=9880, user_time=0.0, system_time=0.0), pthread(id=1384, user_time=0.015625, system_time=0.0), pthread(id=8104, user_time=0.015625, system_time=0.0), pthread(id=2496, user_time=0.046875, system_time=0.0), pthread(id=9552, user_time=0.0, system_time=0.0), pthread(id=11828, user_time=0.0, system_time=0.0), pthread(id=4492, user_time=0.046875, system_time=0.0), pthread(id=8708, user_time=0.109375, system_time=0.078125), pthread(id=9364, user_time=0.0, system_time=0.0), pthread(id=6464, user_time=0.125, system_time=0.03125), pthread(id=11732, user_time=0.015625, system_time=0.0), pthread(id=11424, user_time=0.0, system_time=0.0), pthread(id=4084, user_time=0.0, system_time=0.0), pthread(id=11776, user_time=0.421875, system_time=0.703125), pthread(id=7684, user_time=0.03125, system_time=0.078125), pthread(id=3676, user_time=0.0, system_time=0.0), pthread(id=4368, user_time=0.0, system_time=0.015625), pthread(id=7308, user_time=0.0, system_time=0.0), pthread(id=2244, user_time=0.0, system_time=0.0), pthread(id=9480, user_time=0.03125, system_time=0.015625), pthread(id=12444, user_time=0.0, system_time=0.03125), pthread(id=6612, user_time=0.0625, system_time=0.359375), pthread(id=2612, user_time=0.0, system_time=0.0), pthread(id=4824, user_time=0.03125, system_time=0.015625), pthread(id=1304, user_time=0.015625, system_time=0.0), pthread(id=8300, user_time=0.0, system_time=0.0), pthread(id=13160, user_time=0.0, system_time=0.0), pthread(id=9536, user_time=0.015625, system_time=0.15625), pthread(id=1320, user_time=0.109375, system_time=0.21875), pthread(id=7560, user_time=0.0, system_time=0.015625), pthread(id=1216, user_time=0.0, system_time=0.0), pthread(id=11700, user_time=0.0, system_time=0.0), pthread(id=13308, user_time=0.0, system_time=0.0), pthread(id=12652, user_time=0.140625, system_time=0.21875), pthread(id=8472, user_time=0.5, system_time=0.265625), pthread(id=2992, user_time=0.0, system_time=0.0), pthread(id=5632, user_time=0.40625, system_time=0.1875), pthread(id=7668, user_time=0.265625, system_time=1.09375), pthread(id=10864, user_time=0.40625, system_time=1.59375), pthread(id=1468, user_time=0.21875, system_time=0.09375), pthread(id=6304, user_time=0.0, system_time=0.0), pthread(id=13148, user_time=0.0, system_time=0.0), pthread(id=2376, user_time=0.03125, system_time=0.0), pthread(id=7456, user_time=0.171875, system_time=0.546875), pthread(id=8256, user_time=0.0, system_time=0.0), pthread(id=4068, user_time=0.03125, system_time=0.015625), pthread(id=9436, user_time=1.421875, system_time=0.796875), pthread(id=1444, user_time=0.015625, system_time=0.046875), pthread(id=11544, user_time=0.0, system_time=0.0), pthread(id=9256, user_time=0.0, system_time=0.0), pthread(id=8476, user_time=0.0, system_time=0.0), pthread(id=12488, user_time=0.0, system_time=0.0), pthread(id=12412, user_time=0.015625, system_time=0.078125), pthread(id=12752, user_time=0.0, system_time=0.015625), pthread(id=4712, user_time=0.015625, system_time=0.015625), pthread(id=12268, user_time=0.0625, system_time=0.0), pthread(id=1168, user_time=0.03125, system_time=0.03125), pthread(id=1728, user_time=0.0, system_time=0.015625), pthread(id=7400, user_time=0.0, system_time=0.0), pthread(id=12888, user_time=0.03125, system_time=0.140625), pthread(id=11452, user_time=0.03125, system_time=0.046875), pthread(id=10152, user_time=0.0, system_time=0.0), pthread(id=8648, user_time=0.0, system_time=0.0), pthread(id=9516, user_time=0.0, system_time=0.0), pthread(id=9000, user_time=0.0, system_time=0.0), pthread(id=8512, user_time=0.0, system_time=0.0), pthread(id=10796, user_time=0.0, system_time=0.0), pthread(id=10084, user_time=0.0, system_time=0.0), pthread(id=13196, user_time=0.0, system_time=0.0), pthread(id=7432, user_time=0.0, system_time=0.0), pthread(id=11456, user_time=0.0, system_time=0.0), pthread(id=10536, user_time=0.0, system_time=0.0), pthread(id=12840, user_time=0.0, system_time=0.0), pthread(id=7964, user_time=0.328125, system_time=1.203125), pthread(id=5688, user_time=0.0625, system_time=0.03125), pthread(id=8220, user_time=0.0, system_time=0.0625), pthread(id=1828, user_time=0.15625, system_time=0.109375), pthread(id=7060, user_time=0.0, system_time=0.0), pthread(id=9368, user_time=0.0, system_time=0.0), pthread(id=7896, user_time=0.015625, system_time=0.015625), pthread(id=9888, user_time=0.03125, system_time=0.0), pthread(id=1140, user_time=0.015625, system_time=0.015625), pthread(id=13208, user_time=0.078125, system_time=0.0), pthread(id=10948, user_time=0.015625, system_time=0.0), pthread(id=8108, user_time=0.0, system_time=0.0), pthread(id=1860, user_time=0.0, system_time=0.015625), pthread(id=13416, user_time=0.0, system_time=0.0)] >>> p.environ()#进程P的环境变量 {'1830B7BD-F7A3-4C4D-989B-C004DE465EDE': 'd18:d2028', '360DIR': 'D:\\Program Files (x86)\\360\\360safe', '360SAFEDIR': 'D:\\Program Files (x86)\\360\\360safe', 'ALLUSERSPROFILE': 'C:\\ProgramData', 'APPDATA': 'C:\\Users\\YJEthan\\AppData\\Roaming', 'ASL.LOG': 'Destination=file', 'CLASSPATH': '.;H:\\Java\\jdk1.7.0_79\\lib;H:\\Java\\jdk1.7.0_79\\lib\\tools.jar', 'COMMONPROGRAMFILES': 'C:\\Program Files (x86)\\Common Files', 'COMMONPROGRAMFILES(X86)': 'C:\\Program Files (x86)\\Common Files', 'COMMONPROGRAMW6432': 'C:\\Program Files\\Common Files', 'COMPUTERNAME': 'DESKTOP-TQ6HH1U', 'COMSPEC': 'C:\\WINDOWS\\system32\\cmd.exe', 'DRIVERDATA': 'C:\\Windows\\System32\\Drivers\\DriverData', 'FPS_BROWSER_APP_PROFILE_STRING': 'Internet Explorer', 'FPS_BROWSER_USER_PROFILE_STRING': 'Default', 'HOMEDRIVE': 'C:', 'HOMEPATH': '\\Users\\YJEthan', 'JAVA_HOME': 'H:\\Java\\jdk1.7.0_79', 'LOCALAPPDATA': 'C:\\Users\\YJEthan\\AppData\\Local', 'LOGONSERVER': '\\\\DESKTOP-TQ6HH1U', 'NUMBER_OF_PROCESSORS': '4', 'ONEDRIVE': 'C:\\Users\\YJEthan\\OneDrive', 'OS': 'Windows_NT', 'PATH': 'C:\\Program Files (x86)\\HP\\NV\\lib\\shunra\\vcat;D:\\app\\2016551319\\product\\12.2.0\\dbhome_1\\bin;C:\\Program Files (x86)\\Common Files\\Oracle\\Java\\javapath;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\;C:\\WINDOWS\\System32\\OpenSSH\\;C:\\Program Files (x86)\\NVIDIA Corporation\\PhysX\\Common;H:\\MATLAB\\R2017b\\runtime\\win64;H:\\MATLAB\\R2017b\\bin;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\;C:\\WINDOWS\\System32\\OpenSSH\\;D:\\TDM-GCC-64\\bin;C:\\Program Files (x86)\\HP\\NV\\lib\\thirdparty\\safenet\\LDK\\7.0;d:\\WinSCP\\;d:\\Program Files\\Git\\cmd;H:\\Python\\Scripts\\;H:\\Python\\;C:\\Users\\YJEthan\\AppData\\Local\\Microsoft\\WindowsApps;H:\\Java\\jdk1.7.0_79\\bin;H:\\Java\\jdk1.7.0_79\\jre\\bin;H:\\PyCharm 2019.1.1\\bin;d:\\Microsoft VS Code\\bin;H:\\CodeBlocks\\MinGW\\bin;D:\\Firfox\\firefox.exe', 'PATHEXT': '.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC', 'PROCESSOR_ARCHITECTURE': 'x86', 'PROCESSOR_ARCHITEW6432': 'AMD64', 'PROCESSOR_IDENTIFIER': 'Intel64 Family 6 Model 60 Stepping 3, GenuineIntel', 'PROCESSOR_LEVEL': '6', 'PROCESSOR_REVISION': '3c03', 'PROGRAMDATA': 'C:\\ProgramData', 'PROGRAMFILES': 'C:\\Program Files (x86)', 'PROGRAMFILES(X86)': 'C:\\Program Files (x86)', 'PROGRAMW6432': 'C:\\Program Files', 'PSMODULEPATH': '%ProgramFiles%\\WindowsPowerShell\\Modules;C:\\WINDOWS\\system32\\WindowsPowerShell\\v1.0\\Modules', 'PUBLIC': 'C:\\Users\\Public', 'PYCHARM': 'H:\\PyCharm 2019.1.1\\bin;', 'SSLKEYLOGFILE': 'C:\\Users\\YJEthan\\Desktop\\test\\sslkeylog.log', 'SYSTEMDRIVE': 'C:', 'SYSTEMROOT': 'C:\\WINDOWS', 'TEMP': 'C:\\Users\\YJEthan\\AppData\\Local\\Temp', 'TMP': 'C:\\Users\\YJEthan\\AppData\\Local\\Temp', 'USERDOMAIN': 'DESKTOP-TQ6HH1U', 'USERDOMAIN_ROAMINGPROFILE': 'DESKTOP-TQ6HH1U', 'USERNAME': 'YJEthan', 'USERPROFILE': 'C:\\Users\\YJEthan', 'WINDIR': 'C:\\WINDOWS'} >>> p.terminate()#终结进程p >>> psutil.test()#模拟ps USER PID %MEM VSZ RSS NICE STATUS START TIME CMDLINE SYSTEM 0 0.0 56.0K 8.0K runni Feb06 54:46 System Idle P SYSTEM 4 0.0 192.0K 156.0K 32 runni Feb06 18:53 System SYSTEM 96 0.6 2.8M 48.9M 32 runni Feb06 00:03 Registry SYSTEM 224 0.1 6.2M 8.4M 32 runni 14:14 00:00 C:\WINDOWS\Sy SYSTEM 356 0.0 488.0K 1.1M 32 runni Feb06 00:00 \SystemRoot\S SYSTEM 440 0.1 2.9M 7.5M 32 runni Feb06 00:01 C:\WINDOWS\sy NETWORK S 464 0.2 9.1M 14.4M 32 runni Feb06 00:41 C:\WINDOWS\sy SYSTEM 592 0.1 1.8M 5.3M 32 runni Feb06 00:05 %SystemRoot%\ SYSTEM 700 0.1 1.5M 6.1M 128 runni Feb06 00:00 wininit.exe SYSTEM 772 0.1 5.8M 8.4M 32 runni Feb06 00:17 C:\WINDOWS\sy ...