Little rookie of the Python learning Path----information Query system

Source: Internet
Author: User

Function Description:

(1) User authentication function, only enter the user name and password to query
(2) can check the employee's Id,name, department, telephone
(3) The query interface keyword is the name, the user through the name to check other related information.
(4) Check out the output user information, if the query fails, the report does not have this user, and then loop up


The Python source code is as follows (importing data by reading external files)

#!/usr/bin/env python# encoding=utf-8# author:sihaogongyuan# date:2015-4-5# desc : 2015-4-5 testimport sysimport os# The current time of the output system and separates ################################### #print   Os.system (' Date '), ' \ n ', ' ################################# ' #假设数据库中的name和password都为adminmanage_name_db = ' admin ' manage_password_db= ' admin ' ################################################################# #定义死循环, Allows the user to directly loop through the items to be queried while true:     #让用户输入管理员名称     manage_name=raw_ Input (' please input your manage name: ')      #如果用户输入的管理员名称和定义的数据库中名称一样, Let the user enter the admin password     if manage_name==manage_name_db:         manage_password=raw_input (' Please input your manage password: ')           #当用户输入的管理员密码和db库中的密码不一致时, prompting the user to enter the admin password again           #直到密码输入成功    &Nbsp;    while manage_password!=manage_password_db:             manage_password=raw_input (' Manage password is error, Please try again: ')          #直到用户密码输对了, jump out of this while loop of the password, Execute the later Else statement         else:              #打印出欢迎界面, come to software              print  ' \033[32mwelcome to my contact_select_software!\033[0m '               #定义用户查询信息代码断 that involves multiple queries from the user, so define the while loop              while True:                  #定义match变量, initial assignment is no, representing mismatch             &Nbsp;    match= ' NO '                   #定义select_name变量, as the queried user name                  select_name=raw_input (' please input you select  Name: ')                 # If the select_name variable is empty, prompt the user to re-enter the user name until non-empty                   #此时直接按回车键, representing the passing of the past is also an empty string, note                  while select_name.strip () = = ":                     select_name=raw_input (' Please input you select name: ')                   #打开外部关联文件/tmp/python/contact.txt, default read-only mode                  select_file=file ('/tmp/python/contact.txt ')                   #为每次读取文件中的每一行, make a loop                  while True:                     # The value of the line variable is to call the ReadLine () function each time, removing one row of content                      line=select_file.readline ()                       #len函数判断该行中的字符串数量, If the number is 0 to the end of the file, it has been read out                       #最后一行, jump outRead a while loop of a file                      if len (line) ==0:                         break                     # When you want to search for the name in the row, output all the contents of that line                      elif select_name in line:                          print  '%s '% (line)                           #把变量match赋值为YES                          match= ' YES '                      else :                          pass                          #pass为空指令, do nothing                   #如果要搜索的用户名在所有的行中都没有的话, Through Len (line) ==0, the last break                  #跳出了读取文件内容的while循环 because the initial match variable content is no, which means no horse                   #配到, the match variable is set to 1 if the search content appears in the file.                 if match!= ' YES ':                     print  ' no match founded '       #当用户输入的管理员账户与db库中的管理员账户不一致的时候, prompting the user to enter the wrong, re-enter      #会跳到最大的while循环那去, Manage_ Name re-accepts the user's input request     else:        print  ' name '  is not funded,try again: '

The/tmp/python/contact.txt format is as follows: (the middle is delimited by the TAB key)

1 Xiaohogn IT 9999999999
2 Xiaopang IT 666666666
3 Xiaofei IT 8888888888

This article is from the "Go to the End" blog, please be sure to keep this source http://3971212.blog.51cto.com/3961212/1629068

Little rookie of the Python learning Path----information Query system

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.