设为首页 加入收藏

TOP

装饰器2(二)
2023-09-23 15:44:23 】 浏览:277
Tags:
x') '''修复技术就是为了让装饰器伪装的更像''' # index() # print(index) # <function index at 0x000002F69849A940> # print(index) # <function index at 0x000002F69849A940> # help(index) @outer def home(): '''这是home函数''' help(home)

有参装饰器(重要)



def outter(source_type, *args1, **kwargs1):
    # 'file', 1, 2, 3, 4, 5, 6,
    # source_type = 'file'
    def login_auth(func):  # 参数个数只能有一个
        def auth(*args, **kwargs): #
            username = input('username:>>>').strip()
            password = input('password:>>>').strip()
            # 2. 比较用户名和密码
            """
                1. 文件中获取用户名和密码
                2. 从MySQL中获取用户名和密码
                3. 从oracle中获取用户名和密码
                4. 从postgresql中获取用户名和密码
            """
            # print(a, b, c, d, e, f)
            if source_type == 'file':
                print('文件中获取用户名和密码')
            elif source_type == 'mysql':
                print('从MySQL中获取用户名和密码')
            elif source_type == 'oracle':
                print('从oracle中获取用户名和密码')
            elif source_type == 'postgresql':
                print('从postgresql中获取用户名和密码')

            if username == 'jerry' and password == '123':
                # 执行函数
                print('登录成功')
                func(source_type, *args, **kwargs)
            else:
                print('用户名或者密码错误')
        return auth
    return login_auth

@outter('file', 1, 2, 3, 4, 5, 6,) # login_auth(home, file)
# @login_auth # login_auth(home, file)
def home():
    pass

home('mysql')
首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇数据分析(以kaggle上的加州房价.. 下一篇python采集数据保存csv, 文件内容..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目