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
相关文章
相关标签/搜索