#!/usr/bin/env python #coding:utf-8 #__author__:Bing import sys,json import time,datetime account = [{"name":"Wang","sex":"male","job":"Designer","email":"test@test.com","address":"New street","phone":"110","age":"32"},\ {"name":"Tang","sex":"Female","job":"Painter","email":"test1@test.com","address":"East street","phone":"120","age":"31"},\ {"name":"Hang","sex":"Female","job":"Driver","email":"test2@test.com","address":"West street","phone":"119","age":"30"},\ ] def info(keyword,type): for i in account: try: if str(keyword) == i[str(type)]: return [i["name"],i["sex"],i["job"],i["email"],i["address"],i["phone"],i["age"]] else: return 0#sys.exit("\033[1;31;47mThere's no information you're looking for.\033[0m") except: return 1#print "\033[1;31;47mYou input error!please input again...\033[0m" def search(): type = raw_input("please enter your search type(name/job/sex/age):") keyword = raw_input("please enter your search keyword(Wang/Designer/Female/18):") result = info(keyword, type) if result and result != 1: print "\033[1;34;47mThis is information you're looking for:\033[0m" print "name:"+result[0] print "sex:"+result[1] print "job:"+result[2] print "email:"+result[3] print "address:"+result[4] print "phone:"+result[5] print "age:"+result[6] ''' test ''' search()