python - python变量声明理解困难
问题描述
我是 Python 的新手,并试图解码一行以移植到 Go。在当前的 python 脚本中,我在大多数类下都遇到了这个声明(dataValue)。
class Keys(object):
AB1 = 0x0FF
AB2 = 0x0A2
dataValue = {'0xffff':None}
@classmethod
def _init(cls):
for ke, vl in vars(cls).items():
- 什么是数据值?0xffff 是键并保持 None 作为值吗?
- vars(cls).items() 返回什么?
- @classmethod 意味着这个类键只使用一次?(我遇到了很多@propoerty 的定义,@classmthods 这些关键字仍然让我感到困惑)
试图通过实际项目来理解这些概念。提前致谢!
解决方案
dataValue
是一个字典变量名称,其中包含key:value
一对'0xffff':None
https://docs.python.org/3/tutorial/datastructures.html。vars(cls).items()
返回具有属性https://docs.python.org/3/library/functions.html#vars__dict__
的模块、类、实例或任何其他对象的属性。__dict__
- 返回另一个函数的函数,通常使用 @wrapper 语法作为函数转换应用。装饰器的常见示例是 classmethod() 和 staticmethod() https://docs.python.org/3/glossary.html#term-decorator https://docs.python.org/3/library/functions.html#classmethod https://docs.python.org/3/library/functions.html#staticmethod。
推荐阅读
- php - 我们在哪里可以找到 wordpress WooCommerce 字段已定义?喜欢(订单 ID:%id%,订单密钥:%order_key%)
- pentaho - 如何从 Pentaho-Kettle 中的 select-sql 获取结果集?
- java - 传递给方法时不将新节点分配给树
- r - 如何在 kable/formattable 表中打印 unicode 符号?
- javascript - Problem with reconnection to replica in mongoose
- haskell - How to make type conversion in Haskell?
- xml - Why does Joomla add xml tag if article contains word "XHTML"?
- c++ - Arduino Serial library cannot find "availableForWrite()" function
- python-3.x - 如何在 Python 中更改 y 轴上缩放因子的字体大小?
- reactjs - 如何控制反应路由器上的链接