随笔分类 -  Python 反射

摘要:# !/usr/bin/env python # -*- coding:utf8 -*- # from lib import account # url = input("请模拟输入 url 页面: ") # # if url.endswith("login"): # r = account.log 阅读全文
posted @ 2021-02-17 21:23 xuwenwei 阅读(85) 评论(0) 推荐(0) 编辑
摘要:当使用__import__(), (嵌套的路径字符串,fromlist=True) # !/usr/bin/env python # -*- coding:utf8 -*- # import lib.test.com # # r = lib.test.com.com_func() # print(r 阅读全文
posted @ 2021-02-17 20:29 xuwenwei 阅读(91) 评论(0) 推荐(0) 编辑
摘要:getattr ;setattr ;hasattr ;delattr 根据字符串的形式去对象(某个模块)中操作其成员。 操作均在内存中执行,并不影响对象。不会修改某个对象(文件) import commons target_func = getattr(commons, 'f1', None) # 阅读全文
posted @ 2021-02-17 20:11 xuwenwei 阅读(33) 评论(0) 推荐(0) 编辑
摘要:反射: 通过字符串额形式,导入模块 通过字符串的形式,去模块中寻找指定函数,并执行函数。 __import__(“字符串形式的模块名称”),就可以导入相应的模块 通过内置函数 getattr(模块名,‘函数的字符串名称’)来指定需要执行的函数 注意找到了函数,还需要在函数名后面加()来执行函数。 / 阅读全文
posted @ 2021-02-17 18:02 xuwenwei 阅读(123) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示