- dict_keys 之间做 &
a = {'name': 'jrl', 'age': 25}
b = {'name': 'tsq'}
c = a.keys() & b.keys()
c = {'name'} # type = set
# 可以通过dict.keys()的&结果, 来判断两个dict之间是否有重复的key
- slots:限制类可添加的属性
In [1]: class Student():
...: __slots__ = ('name', 'age')
...:
In [2]: s1 = Student()
In [3]: s1.name = 'tsq'
In [4]: s1.age = 18
In [5]: s1.sex = 'man'
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-5-786e15638aed> in <module>
----> 1 s1.sex = 'man'
AttributeError: 'Student' object has no attribute 'sex'
使用__slots__要注意,__slots__定义的属性仅对当前类起作用,对继承的子类是不起作用的。参考:https://www.liaoxuefeng.com/wiki/897692888725344/923030542875328
- 查看whl依赖
pip install pkginfo
pkginfo -f requires_dist xxxx.whl
# 显示
requires_dist: ['addict', 'numpy', 'Pillow', 'six', 'terminaltables', 'loguru', 'tensorboard', 'future', 'pyyaml', 'pycodestyle', 'autopep8', 'tqdm', 'numba (>=0.53.0)', 'pyntcloud', 'sklearn', 'opencv-python', 'pycocotools (==2.0.2)', 'beeprint', 'scikit-image', 'imgaug', 'imagecorruptions', 'stopit', 'rospkg', 'catkin-tools', "addict ; extra == 'all'", "numpy ; extra == 'all'", "Pillow ; extra == 'all'", "six ; extra == 'all'", "terminaltables ; extra == 'all'", "loguru ; extra == 'all'", "tensorboard ; extra == 'all'", "future ; extra == 'all'", "pyyaml ; extra == 'all'", "pycodestyle ; extra == 'all'", "autopep8 ; extra == 'all'", "tqdm ; extra == 'all'", "numba (>=0.53.0) ; extra == 'all'", "pyntcloud ; extra == 'all'", "sklearn ; extra == 'all'", "opencv-python ; extra == 'all'", "pycocotools (==2.0.2) ; extra == 'all'", "beeprint ; extra == 'all'", "scikit-image ; extra == 'all'", "imgaug ; extra == 'all'", "imagecorruptions ; extra == 'all'", "stopit ; extra == 'all'", "rospkg ; extra == 'all'", "catkin-tools ; extra == 'all'"]