struct.error: unpack requires a buffer of 4 bytes
问题 I want to convert data from a device from bites to float I use the code from this answer bytes to float import struct byte_file = b'+001.80\r' print(type(byte_file)) y = struct.unpack('f' , byte_file) print(y) I get this struct.error: unpack requires a buffer of 4 bytes The correct outcome should be 1.80 do I need to implement a buffer argument ? 回答1: struct is used for binary packed data - data that is not human-readable. b'+001.80\r' is 8 bytes long: b'+', b'0', b'0', b'1', b'.', ... . You