Python - 幾個注意的要點

使用setuptools對包進行安裝

單個項目中對上層的包的調用是很差的python

self和cls

  • cls是class的縮寫,能夠用來調用類內部的靜態方法
  • self就像是C中的this

使用setattr和getattr來對對象進行賦值

pythonclass A:
    def __init__(self):
        self.a = 'a'

a = A() 
setattr(a, 'a', 'b')

>>> a.a
'b'

靜態的方法

@staticmethod
相關文章
相關標籤/搜索