不常用的python符号和函数记录

1. vars()函数:

与args和class相关 转为字典形式

2. 星号

https://blog.csdn.net/zkk9527/article/details/88675129

a={'A':1,'B':2,'C':3}
print(a)
print(*a)
-------------------
{'A': 1, 'B': 2, 'C': 3}
A B C

3. 双星号:

化简输入吧

 def check_channel(channel1,channel2,channel3):
        return channel1,channel2,channel3
    channel1,channel2,channel3 = check_channel(**Address)
{'rtsp': 'rtsp://admin~Channels/302', 'helmet_detect': [True, [0, 0, 0, 0, 0, 0, 0, 0]], 'behave_detect': [True, 'None'], 'cellphone_detect': [True, [0, 0, 0, 0, 0, 0, 0, 0]]}
{'rtsp': 'rtsp://admin~Channels/402', 'helmet_detect': [True, 'None'], 'behave_detect': [False, 'None'], 'cellphone_detect': [True, 'None']}
{'rtsp': 'rtsp://admin~Channels/502', 'helmet_detect': [True, [0, 0, 0, 0, 0, 0, 0, 0]], 'behave_detect': [True, 'None'], 'cellphone_detect': [True, [0, 0, 0, 0, 0, 0, 0, 0]]} 

4. Path函数:

https://blog.csdn.net/hxj0323/article/details/113374539

5. hasattr

如果对象有该属性返回 True,否则返回 False。

6. 空列表:# 以三维空列表为例

3d_list = [ [ [] for j in range(9) ] for i in range(9) ]

7. list sort以后获得原来的排序

a=[54,876,45,34,45,13,86]
sorted_id = sorted(range(len(a)),key = lambda k:a[k] )
print(sorted_id)

8. dict+zip

char2id = dict(zip(voc, range(len(voc))))
id2char = dict(zip(range(len(voc)), voc))

9.将list列表写入文件并读取方法汇总

https://blog.csdn.net/as480133937/article/details/93137001

10.collection库处理字符串和字典

https://www.cnblogs.com/luminousjj/p/9342161.html

11.super(class,self).init()

其中class是子类,这段代码的含义是首先找到class的父类,然后将class类的对象转化为父类的对象,让后让这个“被转化”的对象调用自己的__init__()函数。

class child_with_super(father):
def init(self,father_attribute,super_attribute):
super(child_with_super, self).init(father_attribute)
self.super_attribute=super_attribute

12. cv 带中文

img_path = f"all_img/{img_name}.png"
img = cv2.imdecode(np.fromfile(img_path, dtype=np.uint8), 1)
name = f"data_ver2/{img_name}.png"
cv2.imencode('.png', img)[1].tofile(name)

13.withopen 写 list

https://blog.csdn.net/as480133937/article/details/93137001

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值