Python Decorator Job

Source: Internet
Author: User
Tags python decorator

# user_dic={' xiaohong ': ' 123 ', ' Xiaobai ': ' 123 ', ' Xiaohei ': ' 123 '} # With open (' Idpd.txt ', ' W ', encoding= ' utf-8 ') as F: #      f.write (str (user_dic))# with open (' Idpd.txt ', ' R ', encoding= ' Utf-8 ') as F2:#       read=f2.read ()#     print (read)#     user_dic= Eval (read)# writes the User_dic dictionary to the file and imports the file dictionary
#idpd_path=r ' F:\Pycharmprojects\0615\idpd.txt '#idpd_dic={' id ': false, ' password ': false}#def Login (func):#def login (*args,**kwargs):#if idpd_dic[' id '] and idpd_dic[' password ']:#Res=func (*args,**kwargs)#return res#With open (Idpd_path, ' R ', encoding= ' utf-8 ') as F:#Login_dic=eval (F.read ())
Make Cache#From urllib.request import Urlopen#Import OS#cashe_path=r ' F:\Pycharmprojects\0615\makecache.txt '#def make_cashe (func):#def wrapper (*args,**kwargs):#if Os.path.getsize (cashe_path):#print (' \033[45m====> with Cache \033[0m ')#With open (Cashe_path, ' RB ',) as F:#Res=f.read ()#Else:#Res=func (*args,**kwargs)#with open (Cashe_path, ' WB ') as F:a#F.write (RES)#return res#return wrapper#@make_cashe#def get (URL):#return Urlopen (URL). Read ()

#declare an empty dictionary at the beginning of the file, and then add an adorner to each function to do the automatic addition to the dictionary#fun_dic={}#def Outer (key):#def outer (func):#def wrapper (*args,**kwargs):#Fun_dic[key]=func#return wrapper#return outer# #@Outer (' F1 ')#def f1 ():#print (' from F1 ')#@Outer (' F2 ')#def f2 ():#print (' from F2 ')#@Outer (' F3 ')#def f3 ():#print (' fromt f3 ')#F1 ()#F2 ()#f3 ()#print (fun_dic)

#i=input (' ID: ')#password=input (' Password: ')#if I in Login_dic and password in login_dic:#print (' login successfully ')#idpd_dic[' id ']=true#idpd_dic[' password ']=true#Res=func (*args,**kwargs)#return res#Else:#Print (' login error ')#Return Login#after the authentication is successful, it is no longer necessary to run other certificates
#declare an empty dictionary at the beginning of the file, and then add an adorner to each function to do the automatic addition to the dictionary#fun_dic={}#def Outer (key):#def outer (func):#def wrapper (*args,**kwargs):#Fun_dic[key]=func#return wrapper#return outer# #@Outer (' F1 ')#def f1 ():#print (' from F1 ')#@Outer (' F2 ')#def f2 ():#print (' from F2 ')#@Outer (' F3 ')#def f3 ():#print (' fromt f3 ')#F1 ()#F2 ()#f3 ()#print (fun_dic)

Python Decorator Job

Related Article

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.