Python Blog Park example, focus on using adorners

Source: Internet
Author: User

# -*- coding:utf-8 -*-import timelogin_state = falseuser_dict = {' Username ':  none}def register ():  #  registration function     while True:         username = input ("Please enter your registered account:"). Strip ()          password = input ("Please enter your registration password:"). Strip ()          with open ("register",  encoding= "UTF-8") as reg:             for i in reg:                 list_reg = i.strip (). Split (', ')                  if username  == list_reg[0]:                    &nbsP;print ("User name already exists, please re-enter")                      break             else:                 With open ("register",  encoding= "UTF-8",  mode= "a") as ligo:                     ligo.write (' \n{},{} ' . Format (Username, password))                      print ("Registration successful")                      return truedef login ():   #  Login Function     global login_state    global user _dict    i = 0  #  counters     while i < 3:  #  After more than 3 times, the login failed         username = input ("Please enter your account:"). Strip ()          password = input ("Please enter your password:"). Strip ()   #  Remove space and change         with open (' register ',  encoding= ' UTF-8 ') as  f1:            for line in f1 :  #  Loop reads the contents of the registration file                  line_list = line.strip (). Split (', ')                  if username == line_list[0] and  password == line_list[1]:                 &nBsp;   print ("******* Landing success *******")                      login_state = True                     user_ dict = line_list[0]                     return True             else:                 print ("Account or password input error")             i  += 1def log (E):     def loge ():         log_time = time.strftime ("%y-%m-%d %h:%m:%s",  time.localtime ())           With open ("Log",  encoding= "UTF-8",  mode= "a")  as logg:             logg.write (' \n{},{} landed and executed the {} function '. Format (log_time, user_dict,  e.__name__))         e ()     return  Logedef jian_ce (f):  #  authentication function, detects whether the user is logged in     def inner ():         global login_state        if  login_state == False:             Print ("You have not logged in, please log in before executing the program")             login ()          else:             f ()     return innerdef logoff ():  #  logout function      global login_state    if login_state == true:         login_state = false        print ("logout success")          return login_state    else:         print ("You have not logged in, do not need to log out") @jian_ce   #  syntax sugar, decorator @logdef wen_ Zhang ():     print ("This is the article page") @jian_ce   #  syntax sugar, decorator @logdef ri_ji ():     print ("This is the Diary page") @jian_ce   #  syntax sugar, decorator @logdef ping_lun ():     print ("This is the Comment page") @jian_ce   #  syntax sugar, adorner @logdef shou_cang ():     print ( "This is the Collection page") xu_dict = {  #  defines a dictionary that holds the serial number correspondence function     1: login,     2: register,    3: wen_zhang,    4:  Ri_ji,   &nbSp;5: ping_lun,    6: shou_cang,    7: logoff}while  true:    print ("-------Welcome to Blog Park-------        &NBSP;1: Please login         2: please register          3: Article page         4: Diary page          5: Comment Page         6: Favorites Page          7: Logoff         8: Exit program           ')     xu_hao = input ("Please enter serial number:"). Strip ()     if  Xu_hao.isdigit ():         xu_hao = int (Xu_hao)          if xu_hao > 0 and xu_hao <= len ( XU_DICT):     &Nbsp;       xu_dict[xu_hao] ()          elif xu_hao == 8:             Break            print ("Good-bye!" Exit program Success ")         else:             print ("The serial number you entered does not exist")     else:         print ("The serial number you entered has illegal characters")


Python Blog Park example, focus on using adorners

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.