Python dir() 和 __dir__
来源:互联网 发布:java获取上传文件名称 编辑:程序博客网 时间:2024/05/21 14:06
dir()
1. dir() 是一个函数, 返回list
2. dir() 输出对象的所有属性,包括__dir__ 中的属性, __dir__ 是dir 的子集
__dir__
1. 返回的是一个字典
2. 并不是所有的对象都有__dir__ 属性, 许多内建类型就没有__dir__, 如list
3. python的实例拥有它们自己的__dict__,而它们对应的类也有自己的__dict__:
>>> class Foo(object):... bar = 'spam'... >>> Foo().__dict__{}>>> Foo.__dict__dict_proxy({'__dict__': <attribute '__dict__' of 'Foo' objects>, '__weakref__': <attribute '__weakref__' of 'Foo' objects>, '__module__': '__main__', 'bar': 'spam', '__doc__': None})
dir()函数会遍历Foo,Foo()和object的__dict__属性,从而为Foo类,它的实例以及它所有的被继承类创建一个完整有效的属性列表。
阅读全文
0 0
- Python dir() 和 __dir__
- python __str__(),__dir__(),__doc__
- python基础-dir()和__dict__
- python中的dir()和__dict__
- python dir()
- python dir()
- python dir()
- python dir()和vars()的区别
- python dir()和vars()的区别
- python文档帮助help()和dir()
- Python的type, str, dir和callable函数
- Python中有用的三个工具:dir, type和help
- 【python】-file/dir
- python dir函数
- python dir & vars
- python dir()函数作用
- python dir __dict__
- python函数 - dir()
- 文章标题
- 关于ReportingService配置邮件发送报表到其他邮箱的配置
- Java编程思想之泛型(拓展)
- Spring Boot REST API错误处理指南
- C++ tinyxml的封装与使用
- Python dir() 和 __dir__
- 客户端自动关闭键盘
- 个人笔记5
- mybatis中foreach的使用
- nodejs以及JavaScript提升
- Python 手记(一):生成器与迭代器
- bzoj1050 [HAOI2006]旅行comf(并查集)
- 安卓第三方支付之支付宝支付
- 打磨渗透测试人员的利器Kali Linux