Amelia
Amelia

Reputation: 41

Difficulty in understanding the python variable declaration

I am newbie to Python and trying to decode a line to port over to Go. In the current python script, I come across this declaration (dataValue) under most of the class.

class Keys(object):
   AB1 = 0x0FF
   AB2 = 0x0A2
   dataValue = {'0xffff':None}

   @classmethod
   def _init(cls):
     for ke, vl in vars(cls).items():
       
  1. What is dataValue? Is 0xffff a key and hold None as a value?
  2. What does vars(cls).items() return?
  3. @classmethod means this class keys is used only once? (I came across many definitions for @propoerty, @classmthods still these keywords confuses me)

Trying to understand the concepts thru real projects. Thanks in advance!

Upvotes: 0

Views: 85

Answers (1)

Qwerty
Qwerty

Reputation: 91

  1. dataValue is a dictionary variable name, which has in it key:value pair of '0xffff':None https://docs.python.org/3/tutorial/datastructures.html.
  2. vars(cls).items() Return the __dict__ attribute for a module, class, instance, or any other object with a __dict__ attribute https://docs.python.org/3/library/functions.html#vars.
  3. A function returning another function, usually applied as a function transformation using the @wrapper syntax. Common examples for decorators are classmethod() and 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.

Upvotes: 3

Related Questions