#!/bin/env python#coding:utf-8filename = '/py/day01/contact/userinfo ' init_username = ' Frame ' init_password = ' frame ' success = 0while true: username = raw_input ("username: "). Strip () password = raw_input (" password: "). Strip () if username == init_username: while password != init_password: password = raw_input ("Password error,try again: "). Strip () else: print "Welcome to use the program" success = 1 break else: print " Username error "#当用户登录成功时, execute this code if success == 1: while true: search_name = raw_input ("Search Name: "). Strip () #当用户输入的是quit时, exit program if search_name == ' Quit ': break# If the user does not enter anything, all entries are displayed if not search_name: userinfo = file (filename) info = userinfo.readlines () userinfo.close () for items in info: print items, #使用match变量实现模糊查询 else: userinfo = file (filename) match = 0 while True: info = userinfo.readline () #当info的长度为0时, Note that the contents of the UserInfo file have been read, close the file, and exit the current loop if not len (Info): userinfo.close () &nbSp; break# uses the member relationship action (in) to implement the fuzzy query, and if so, displays the entry and sets the match = 1 if search_name in info: print "match item: %s" % info match = 1# If there has been no match, match is 0 if match == 0: print "No match item"
This article is from the "Hezhang" blog, make sure to keep this source http://hezhang.blog.51cto.com/1347601/1700594
Python fuzzy query