Python 3 Building an array of bytes

后端 未结 6 753
终归单人心
终归单人心 2020-12-29 01:44

I need to build a tcp frame with raw binary data, but all examples and tutorials I\'ve found talking about bytes always involve conversion from a string, and that\'s not wha

6条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-29 02:23

    agf's bytearray solution is workable, but if you find yourself needing to build up more complicated packets using datatypes other than bytes, you can try struct.pack(). http://docs.python.org/release/3.1.3/library/struct.html

提交回复
热议问题