python如何實現(xiàn)不用裝飾器實現(xiàn)登陸器小程序
更新時間:2019年12月14日 11:51:31 作者:Iceberg_710815
這篇文章主要介紹了python如何實現(xiàn)不用裝飾器實現(xiàn)登陸器小程序,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
這篇文章主要介紹了python如何實現(xiàn)不用裝飾器實現(xiàn)登陸器小程序,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
下面代碼演示了不使用裝飾器實現(xiàn)用戶登陸功能的小程序,在python3.x下可正常運(yùn)行
#!/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!")
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
使用Python腳本從文件讀取數(shù)據(jù)代碼實例
這篇文章主要介紹了使用Python腳本從文件讀取數(shù)據(jù)代碼實例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2020-01-01淺談Tensorflow 動態(tài)雙向RNN的輸出問題
今天小編就為大家分享一篇淺談Tensorflow 動態(tài)雙向RNN的輸出問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-01-01Python 機(jī)器學(xué)習(xí)工具包SKlearn的安裝與使用
Sklearn(全稱 SciKit-Learn),是基于 Python 語言的機(jī)器學(xué)習(xí)工具包。本文將簡單的介紹SKlearn安裝與使用,想要入坑機(jī)器學(xué)習(xí)的同學(xué)可以參考下2021-05-05Python中super().__init__()測試以及理解
__init__()一般用來創(chuàng)建對象的實例變量,或一次性操作,super()用于調(diào)用父類的方法,可用來解決多重繼承問題,下面這篇文章主要給大家介紹了關(guān)于Python中super().__init__()測試及理解的相關(guān)資料,需要的朋友可以參考下2021-12-12