Python读取实时数据流示例
发布时间:2020-08-20 13:39:01
来源:脚本之家
阅读:57
作者:Python之魂
1、#coding:utf-8
chose = [
('foo',1,2),
('bar','hello'),
('foo',3,4)
]
def do_foo(x,y):
print('foo',x,y)
def do_bar(s):
print('bar',s)
for tag,*args in chose:
if tag == 'foo':
do_foo(*args)
elif tag == 'bar':
do_bar(*args)
line = 'nobody:*:-2:-2:Unprivileged User:/var/empty:/usr/bin/false'
uname,*fields,homedir,sh = line.split(':')
print(sh)
from collections import deque
def search(lines, pattern, history=5):
previous_lines = deque(maxlen=history)
for li in lines:
if pattern in li:
yield li, pr