Python标准库:内置函数vars([object])
2015-06-14 07:51
387 查看
本函数是实现返回对象object的属性和属性值的字典对象。如果默认不输入参数,就打印当前调用位置的属性和属性值,相当于locals()的功能。如果有参数输入,就只打印这个参数相应的属性和属性值。
例子:
结果输出如下:
{'Foo': <class '__main__.Foo'>, 'B': <class '__main__.B'>, '__name__': '__main__', '__doc__': None, '__spec__': None,...
{'__module__': '__main__', 'a': 1, '__dict__': <attribute '__dict__' of 'Foo' objects>, '__weakref__': <attribute '__weakref__' of 'Foo' objects>, '__doc__': None}
{}
蔡军生 QQ:9073204 深圳
例子:
#vars() print(vars()) class Foo: a = 1 print(vars(Foo)) foo = Foo() print(vars(foo))
结果输出如下:
{'Foo': <class '__main__.Foo'>, 'B': <class '__main__.B'>, '__name__': '__main__', '__doc__': None, '__spec__': None,...
{'__module__': '__main__', 'a': 1, '__dict__': <attribute '__dict__' of 'Foo' objects>, '__weakref__': <attribute '__weakref__' of 'Foo' objects>, '__doc__': None}
{}
蔡军生 QQ:9073204 深圳
相关文章推荐
- 学习笔记(objective-c)-多态
- 【ObjectC】oc中的内存分配
- error: while loading shared libraries : countlib.so : cannnot open shared object file : No such fil
- Faq_flask : AttributeError: ‘module’ object has no attribute ‘autoescape’
- Objective-C语法之扩展(Extension)的使用
- Objective-C语法之字符串NSString去掉前后空格或回车符(可以是NSCharacterSet类型的其它字符)
- Objective-C语法之可变参数
- Objective-C语法之NSDictionary和NSMutableDictionary
- Objective-C语法之指针型参数
- Objective-C语法之nonatomic和atomic之间的区别
- Objective-C语法之NSSortDescriptor
- Objective-C语法之NSPredicate的使用
- jsrender for object
- jsrender for array 和for object语法
- objective-c集合类
- 学习笔记(objective-c)-继承
- JavaScript Object 对象
- 当json中object嵌套,datagrid中如何显示数据
- Objective-C NSString字符串操作总结
- Flex 4.6 在mxml中创建复杂Object