Lesson0402_GetatrrWebsite.py

#!/usr/bin/env/python
#-*-coding:utf-8-*- #Author:LingChongShi #查看源码Ctrl+左键 def index():
print('欢迎访问XX网站') def login():
print('登录成功') def logout():
print('退出登录') class People(object):
country='China'
def __init__(self):
pass
def people_info(self):
print('People类中people_info函数')
Lesson0403_Getattr.py
#!/usr/bin/env/python
#-*-coding:utf-8-*- #Author:LingChongShi #查看源码Ctrl+左键 '''
getattr():根据字符串的形式去某个模块中查找X函数
hasattr():根据字符串的形式去某个模块判断X函数是否存在
setattr():根据字符串的形式去某个模块设置X函数
delattr():根据字符串的形式去某个模块删除X函数
'''
import Lesson04_Package.Lesson0402_GetatrrWebsite
'''getattr(object,name,default):
1、object:对象(模块)
2、name:属性(函数/方法)
3、default:无对应属性,返回的值,
4、有对应属性,返回对象属性值
'''
getder=getattr(Lesson04_Package.Lesson0402_GetatrrWebsite,'index','-1')
print(getder)
getder() obj=Lesson04_Package.Lesson0402_GetatrrWebsite.People()
getclass=getattr(obj,'people_info','-1')
getclass() '''hasattr(object,name):
1、object:对象(模块)
2、name:属性(函数/方法)
3、如果对象有该属性返回True,否则返回False
'''
has=hasattr(Lesson04_Package.Lesson0402_GetatrrWebsite,'login')
print(has) obj=Lesson04_Package.Lesson0402_GetatrrWebsite.People()
hasclass=hasattr(obj,'people_info')
print(hasclass) '''setattr(object,name,value):
1、object:对象(模块)
2、name:属性(函数/方法)
3、value:属性值
4、无返回值
'''
set=setattr(Lesson04_Package.Lesson0402_GetatrrWebsite,'str','添加的字符串')
has1=hasattr(Lesson04_Package.Lesson0402_GetatrrWebsite,'str')
print(has1)
get1=getattr(Lesson04_Package.Lesson0402_GetatrrWebsite,'str')
print(get1) obj=Lesson04_Package.Lesson0402_GetatrrWebsite.People()
setclass=setattr(obj,'exit','退出')
hascalss=hasattr(obj,'exit')
print(hasclass) '''delattr(object,name):
1、object:对象(模块)
2、name:属性(函数/方法)
3、无返回值
'''
del1=delattr(Lesson04_Package.Lesson0402_GetatrrWebsite,'logout')
has2=hasattr(Lesson04_Package.Lesson0402_GetatrrWebsite,'logout')
print(has2)
# get2=getattr(Lesson04_Package.Lesson0402_GetatrrWebsite,'logout')
# print(get2) obj=Lesson04_Package.Lesson0402_GetatrrWebsite.People
hasclass=hasattr(obj,'people_info')
print(hasclass)
delclass=delattr(obj,'people_info')
hasclass=hasattr(obj,'people_info')
print(hasclass)

最新文章

  1. C++ 代码优化
  2. jquery + header
  3. Silverlight类百度文库在线文档阅读器
  4. Android判断网路是否畅通加权限
  5. Apache2.4权限配置(原创帖-转载请注明出处)
  6. 关于 XMLHttpRequest对象的onreadyStateChange方法
  7. loadrunner关联和事务
  8. IOS-UITextField键盘不隐藏问题
  9. 安装Office 2010后出现正在配置
  10. Lining.js - 为CSS提供 ::nth-Line 选择器功能
  11. OSWatcher Black Box
  12. ubutu之jdk安装
  13. 安装courier-authlib找不到mysqlclient.so文件
  14. IntelliJ IDEA:Getting Started with Spring MVC, Hibernate and JSON实践
  15. Java Script基础(二) 基本语法
  16. C# 类与接口的几个问题的总结(待续)
  17. 使用commons-fileupload进行上传
  18. canvas动画——粒子系统(1)
  19. 28、初识socket(subprocess模块)
  20. MongoDB学习总结(二)

热门文章

  1. HTML5 随手记(4)
  2. ASP.NET Core 异常和错误处理 - ASP.NET Core 基础教程 - 简单教程,简单编程
  3. Android Studio怎样提示函数使用方法
  4. Qt如何绘制(简单深刻,fearlazy的系列文章)
  5. Android发展_备份短信
  6. MySQL第五个学习笔记 该数据表的操作
  7. 汉顺平html5课程分享:6小时制作经典的坦克大战!
  8. intel dpdk IPv4 Fragmentation Sample Application 测试
  9. 最简单的IdentityServer实现——IdentityServer
  10. glibc内存管理方式