怎么使用python实现不用装饰器制作登录器小程序-创新互联

这篇文章主要介绍怎么使用python实现不用装饰器制作登录器小程序,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

在坡头等地区,都构建了全面的区域性战略布局,加强发展的系统性、市场前瞻性、产品创新能力,以专注、极致的服务理念,为客户提供网站设计制作、成都网站制作 网站设计制作专业公司,公司网站建设,企业网站建设,成都品牌网站建设,成都全网营销推广,成都外贸网站制作,坡头网站建设费用合理。

下面代码演示了不使用装饰器制作用户登录功能的小程序,在python3.x下可正常运行

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Nov 26 15:26:58 2019

@author: root
"""

def menu():
  print('choice'.center(50,'-'))
  msg = '''
  1. home
  2. finance
  3. book
  4. exit
  '''
  print(msg)
  print("".center(50,'-'))
 
def login(login_flat,choice):
  if not login_flat:
    while True:
      username = str(input("username:"))
      password = str(input("password:"))
      if choice == '1':
        home()
        with open('jingdong.txt','r') as f1:
          for line in f1:
            element = line.split(" ",1)
            print(element[0])
            print(element[1])
            if username.strip() == element[0].strip() and password.strip() == element[1].strip():
              print("log in successful!")
              return True
            print("failed to log in!,try it again!")
      elif choice == '2':
        finance()
        with open('weixin.txt','r') as f2:
          for line in f1:
            element = line.split(" ",1)
            if username.strip() == element[0].strip() and password.strip() == element[1].strip():
              print("log in successful!")
              return True
            print("failed to log in!,try it again!")   
      elif choice == '3':
        book()
        with open('jingdong.txt','r') as f3:
          for line in f3:
            element = line.split(" ",1)
            if username.strip() == element[0].strip() and password.strip() == element[1].strip():
              print("log in successful!")
              return True
            print("failed to log in!,try it again!")              
  else:
    print("You have logged in before!")
    return True
#@login(login_flat,choice)            
def home():
  print("home.....")
#@login(login_flat,choice) 
def finance():
  print("finance.....")
#@login(login_flat,choice) 
def book():
  print("book.....")

  
login_flag = False
while True:
  menu()
  choice = input("your choice:")
  if choice == '1':
    login_flag = login(login_flag,choice)
  elif choice == '2':
    login_flag = login(login_flag,choice)
  elif choice == '3':
    login_flag = login(login_flag,choice)
  elif choice == '4':
    print('bye-bye')
    break
  else:
    print("wrong input ,try it again!")

以上是“怎么使用python实现不用装饰器制作登录器小程序”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注创新互联成都网站设计公司行业资讯频道!

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。

网页名称:怎么使用python实现不用装饰器制作登录器小程序-创新互联
当前路径:https://www.cdcxhl.com/article10/jojdo.html

成都网站建设公司_创新互联,为您提供云服务器微信小程序网站设计品牌网站建设域名注册移动网站建设

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

搜索引擎优化