[英]What's the Pythonic way to append to a bytearray a list?
I'm trying to append the contents of a list (which only contains hex numbers) to a bytearray. 我正在尝试将列表的内容(仅包含十六进制数字)附加到bytearray。 Right now I'm doing this and it works: 现在我正在做这个并且它有效:
payload = serial_packets.get()
final_payload = bytearray(b"StrC")
final_payload.append(len(payload))
for b in payload:
final_payload.append(b)
However, I believe it's not very Pythonic. 但是,我相信它不是非常Pythonic。 Is there a better way to do this? 有一个更好的方法吗?
tldr; tldr; How can I append payload to final_payload in a more Pythonic way? 如何以更加Pythonic的方式将有效负载附加到final_payload?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.