In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces the relevant knowledge of how to use the python byte array, the content is detailed and easy to understand, the operation is simple and fast, and it has a certain reference value. I believe you will gain something after reading this article on how to use the python byte array. Let's take a look at it.
1. The elements of bytes and bytearray are integers between 0255and 255, but any string can be stored in a character encoding scheme. Byte array slices or corresponding byte arrays; byte groups can display ASCII characters directly.
S = 'Helio è re í' b_arr = bytes (s, 'utf_8') print (type (b_arr)) print (type (b_arr)) for b in b_arr: print (b, end='') print () print ('element of bytes is int number', b_arr [0]) print (' splice of bytes is bytes',end =') b_arr_splice = b_arr [: 1] print (b_arr_splice) num_b_arr = bytes
2. The struct module provides to convert the packaged byte sequence conversion section sequence into tuples composed of different types of fields, and there are also some functions for reverse conversion to convert the tuples into packaged byte sequences. This module can handle bytes,bytearray and memoryview objects.
Import structrecord_format = 'hd4s'pack_bytes = struct.pack (record_format, 7,3.14) print (type (pack_bytes)) print (pack_bytes) with open (' struct.b', 'wb') as fp: fp.write (pack_bytes) record_size = struct.calcsize (record_format) with open (' struct.b', 'rb') as fp: record_bs = fp.read (record_size) print (struct.unpack (record_format) Record_bs)) this is the end of the article on "how to use python byte arrays" Thank you for reading! I believe you all have a certain understanding of the knowledge of "how to use python byte arrays". If you want to learn more, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.