[python][高级语法]:知识记录

  • 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'"]
  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值