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 相关文章推荐
使用django-suit为django 1.7 admin后台添加模板
Nov 18 Python
Python多线程编程(二):启动线程的两种方法
Apr 05 Python
Python 使用PIL numpy 实现拼接图片的示例
May 08 Python
Python读取数据集并消除数据中的空行方法
Jul 12 Python
用Python读取几十万行文本数据
Dec 24 Python
python+pyqt5实现24点小游戏
Jan 24 Python
Python图片的横坐标汉字实例
Dec 04 Python
python 爬虫 实现增量去重和定时爬取实例
Feb 28 Python
在Mac中配置Python虚拟环境过程解析
Jun 22 Python
Python基础教程之输入输出和运算符
Jul 26 Python
使用Python画了一棵圣诞树的实例代码
Nov 27 Python
pycharm 快速解决python代码冲突的问题
Jan 15 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
smarty简单入门实例
2014/11/28 PHP
PHP中Restful api 错误提示返回值实现思路
2016/04/12 PHP
微信支付开发订单查询实例
2016/07/12 PHP
实例分析PHP中PHPMailer发邮件
2017/12/13 PHP
php 后端实现JWT认证方法示例
2018/09/04 PHP
PHP使用PDO创建MySQL数据库、表及插入多条数据操作示例
2019/05/30 PHP
学习ExtJS 访问容器对象
2009/10/07 Javascript
11款基于Javascript的文件管理器
2009/10/25 Javascript
js function定义函数使用心得
2010/04/15 Javascript
jquery 插件学习(二)
2012/08/06 Javascript
js、css、img等浏览器缓存问题的2种解决方案
2013/10/23 Javascript
将HTML的左右尖括号等转义成实体形式的两种实现方式
2014/05/04 Javascript
单元选择合并变色示例代码
2014/05/26 Javascript
用box固定长宽实现图片自动轮播js代码
2014/06/09 Javascript
checkbox 选中一个另一个checkbox也会选中的实现代码
2016/07/09 Javascript
关于前后端json数据的发送与接收详解
2017/07/30 Javascript
什么是Vue.js框架 为什么选择它?
2017/10/17 Javascript
在Vue组件上动态添加和删除属性方法
2018/02/23 Javascript
element-ui 限制日期选择的方法(datepicker)
2018/05/16 Javascript
JS实现获取进今年第几天是周几的方法分析
2018/06/27 Javascript
利用js-cookie实现前端设置缓存数据定时失效
2019/06/18 Javascript
js实现录音上传功能
2019/11/22 Javascript
Vue props中Object和Array设置默认值操作
2020/07/30 Javascript
linux下安装easy_install的方法
2013/02/10 Python
Python中多线程thread与threading的实现方法
2014/08/18 Python
python中scikit-learn机器代码实例
2018/08/05 Python
基于python 等频分箱qcut问题的解决
2020/03/03 Python
在 Python 中使用 7zip 备份文件的操作
2020/12/11 Python
HTML5: Web 标准最巨大的飞跃
2008/10/17 HTML / CSS
瑞士网球商店:Tennis-Point
2020/03/12 全球购物
中英文求职信范文
2014/01/27 职场文书
中学自我评价
2014/01/31 职场文书
给全校老师的建议书
2014/03/13 职场文书
地质灾害防治方案
2014/05/14 职场文书
作风建设演讲稿
2014/05/23 职场文书
详解CSS玩转图片Base64编码
2021/05/25 HTML / CSS