vars([object])

返回__dict__属性的值。
当不传入参数时,和locals()等效。
当函数接收一个参数时,参数可以是模块、类、类实例,或者定义了__dict__属性的对象。

>>> vars(A)
mappingproxy({'__module__': '__main__', 'infoA': 'A', '__dict__': <attribute '__dict__' of 'A' objects>,
'__weakref__': <attribute '__weakref__' of 'A' objects>, '__doc__': None})
>>> class B:
... __dict__ = 'tom'
...
>>> b = B()
>>> b.__dict__
'tom'
>>> vars(b)
'tom'

拓展

模块都有__dict__属性。

这是包含模块符号表的字典。

修改这个字典实际上会改变模块的符号表,但直接赋值给__dict__属性是不可能的(你可以写m .__ dict __ ['a'] = 1,将ma定义为1,但是你不能写m .__ dict__ = {})。

不建议直接修改__dict__

模块表示方法

#内置模块
>>> json
<module 'json' from 'D:\\python\\python3.6\\lib\\json\\__init__.py'>
#非内置模块
>>> sys
<module 'sys' (built-in)>

python内置函数之vars()的更多相关文章

  1. Python内置函数(47)——vars

    英文文档: vars([object]) Return the __dict__ attribute for a module, class, instance, or any other objec ...

  2. Python内置函数(66)——vars

    英文文档: vars([object]) Return the __dict__ attribute for a module, class, instance, or any other objec ...

  3. python 内置函数和函数装饰器

    python内置函数 1.数学相关 abs(x) 取x绝对值 divmode(x,y) 取x除以y的商和余数,常用做分页,返回商和余数组成一个元组 pow(x,y[,z]) 取x的y次方 ,等同于x ...

  4. Python 内置函数笔记

    其中有几个方法没怎么用过, 所以没整理到 Python内置函数 abs(a) 返回a的绝对值.该参数可以是整数或浮点数.如果参数是一个复数,则返回其大小 all(a) 如果元组.列表里面的所有元素都非 ...

  5. 【转】Python 内置函数 locals() 和globals()

    Python 内置函数 locals() 和globals() 转自: https://blog.csdn.net/sxingming/article/details/52061630 1>这两 ...

  6. Python之路(第八篇)Python内置函数、zip()、max()、min()

    一.python内置函数 abs() 求绝对值 例子 print(abs(-2)) all() 把序列中每一个元素做布尔运算,如果全部都是true,就返回true, 但是如果是空字符串.空列表也返回t ...

  7. python内置函数大全(分类)

    python内置函数大全 python内建函数 最近一直在看python的document,打算在基础方面重点看一下python的keyword.Build-in Function.Build-in ...

  8. Python之路Python内置函数、zip()、max()、min()

    Python之路Python内置函数.zip().max().min() 一.python内置函数 abs() 求绝对值 例子 print(abs(-2)) all() 把序列中每一个元素做布尔运算, ...

  9. Python内置函数7

    Python内置函数7 1.propertypython内置的一个装饰器可参考https://blog.csdn.net/u013205877/article/details/77804137 2.q ...

随机推荐

  1. easyui icon的使用相关

    easyui的默认图标有以下这些: .icon-blank{ background:url('icons/blank.gif') no-repeat; } .icon-add{ background: ...

  2. 深度学习Deep learning

    In the last chapter we learned that deep neural networks are often much harder to train than shallow ...

  3. 数学图形(1.35)Kappa curve

    不知道这个曲线和那个运动品牌背靠背有什么关系.阿迪原先的商标是个三叶草,难道背靠背也是由数学图形来的? 以下是维基上的解释. In geometry, the kappa curve or Gutsc ...

  4. C++primer习题--第3章

    本文地址:http://www.cnblogs.com/archimedes/p/cpp-primer-chapter3-ans.html,转载请注明源地址. [习题 2.11]编写程序,要求用户输入 ...

  5. SpringSecurity实现后台管理员登录(二)

    需求:login.ftl页面中登录成功后进入index.ftl页面中 一.pom.xml中添加json转换相关的包 <dependency> <groupId>com.fast ...

  6. Sqlserver DateTime转换成SMALLDATETIME时“产生一个超出范围的值”

    工作中遇到一个问题,A表中字段(DateTime1)的数据类型为DateTime,新建了一张表B的SMALLDATETIME1字段的数据来自A表的DateTime1 但在将A表字段DateTime1导 ...

  7. [Webpack] Create Separate webpack Configs for Development and Production with webpack-merge

    The development and production modes in webpack optimize the output in different ways. In developmen ...

  8. 【转】阻塞与非阻塞socket的优缺点

    转自:http://wenku.baidu.com/link?url=V-TghOmERC0eq0aoXEyhpTw3W5OlqbItwTJE_csI29ysi9vKkCG1lDxq0wWdpImvg ...

  9. Burning widget

    This is a widget that we can see in Nero, K3B, or other CD/DVD burning software. #!/usr/bin/python # ...

  10. npm run build:h5 报错

    1.报错信息 (1)asset size limit: The following asset(s) exceed the recommended size limit (244 KiB). (2)e ...