Python内置函数之filter
#!/usr/bin/env python# coding:utf-8
# @Filename: checkpwd.pt
def show_file(file):
'''Open file and returns the file content'''
fp = open(file)
contentList = fp.readlines()
fp.close()
return contentList
def filter_line(listArg):
'''Filter out the lines that end in /bin/bash in the /etc/passwd'''
if listArg.strip('\n').endswith('/bin/bash'):
return True
else:
return False
def show_user(filterArg):
'''Append the user to list'''
showList=[]
for i in filterArg:
showList.append(i[:i.index(':')])
print showList
if __name__ == '__main__':
file = '/etc/passwd'
clist = show_file(file)
flist = filter(filter_line,clist)
show_user(flist)
页:
[1]