赞
踩
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, previous_lines
previous_lines.append(li)
# Example use on a file
if __name__ == '__main__':
with open(r'./somefiles.py') as f:
for li
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。