python如何实现不用装饰器实现登陆器小程序


Posted in Python onDecember 14, 2019

这篇文章主要介绍了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 相关文章推荐
Python脚本判断 Linux 是否运行在虚拟机上
Apr 25 Python
利用selenium 3.7和python3添加cookie模拟登陆的实现
Nov 20 Python
Python进阶之递归函数的用法及其示例
Jan 31 Python
Django密码系统实现过程详解
Jul 19 Python
Python交互式图形编程的实现
Jul 25 Python
pandas read_excel()和to_excel()函数解析
Sep 19 Python
python图形开发GUI库pyqt5的基本使用方法详解
Feb 14 Python
django自定义非主键自增字段类型详解(auto increment field)
Mar 30 Python
解决pycharm安装第三方库失败的问题
May 09 Python
Python自带的IDE在哪里
Jul 01 Python
python判断是空的实例分享
Jul 06 Python
Python3爬虫中Ajax的用法
Jul 10 Python
python模块和包的应用BASE_PATH使用解析
Dec 14 #Python
python socket通信编程实现文件上传代码实例
Dec 14 #Python
python如何使用socketserver模块实现并发聊天
Dec 14 #Python
python paramiko远程服务器终端操作过程解析
Dec 14 #Python
安装PyInstaller失败问题解决
Dec 14 #Python
django自定义模板标签过程解析
Dec 14 #Python
django序列化serializers过程解析
Dec 14 #Python
You might like
php读取目录及子目录下所有文件名的方法
2014/10/20 PHP
php获取CSS文件中图片地址并下载到本地的方法
2014/12/02 PHP
php身份证号码检查类实例
2015/06/18 PHP
Yii2框架dropDownList下拉菜单用法实例分析
2016/07/18 PHP
thinkPHP利用ajax异步上传图片并显示、删除的示例
2018/09/26 PHP
php + WebUploader实现图片批量上传功能
2019/05/06 PHP
js 判断上传文件大小及格式代码
2013/11/13 Javascript
关于js中for in的缺陷浅析
2013/12/02 Javascript
Javascript中引用示例介绍
2014/02/21 Javascript
angular.element方法汇总
2015/01/07 Javascript
js中日期的加减法
2015/05/06 Javascript
实例教学如何写vue插件
2017/11/30 Javascript
Vue表单demo v-model双向绑定问题
2018/06/29 Javascript
VUE v-model表单数据双向绑定完整示例
2019/01/21 Javascript
vue使用@scroll监听滚动事件时,@scroll无效问题的解决方法详解
2019/10/15 Javascript
ant design vue中日期选择框混合时间选择器的用法说明
2020/10/27 Javascript
js实现弹幕墙效果
2020/12/10 Javascript
python使用cStringIO实现临时内存文件访问的方法
2015/03/26 Python
python开发之for循环操作实例详解
2015/11/12 Python
Python绘制3d螺旋曲线图实例代码
2017/12/20 Python
关于django 数据库迁移(migrate)应该知道的一些事
2018/05/27 Python
对numpy中的where方法嵌套使用详解
2018/10/31 Python
python用pandas数据加载、存储与文件格式的实例
2018/12/07 Python
Python正则表达式实现简易计算器功能示例
2019/05/07 Python
python使用matplotlib绘制折线图的示例代码
2020/09/22 Python
Python  Asyncio模块实现的生产消费者模型的方法
2021/03/01 Python
Watchshop德国:欧洲在线手表No.1
2019/06/20 全球购物
英国No.1体育用品零售商:SportsDirect.com
2019/10/16 全球购物
Java提供了哪些企业应用编程接口
2015/02/13 面试题
Static Nested Class 和 Inner Class的不同
2013/11/28 面试题
影视制作岗位职责
2013/12/04 职场文书
实习教师自我鉴定
2013/12/12 职场文书
军训 自我鉴定
2014/02/03 职场文书
初三学生评语大全
2014/04/24 职场文书
局机关干部群众路线个人对照检查材料思想汇报
2014/10/05 职场文书
机关单位2016年创先争优活动总结
2016/04/05 职场文书