James Wang
James Wang

Reputation: 31

Python - Struct pack error

I was trying to pack a alphabet, for example, A I used struct.pack('c','A'), but the output kept showing

"struct.error: char format requires a bytes object of length 1"

I checked the official documents of all version of Python, the syntax are the same. I'm using version 3.3.2.

Does anyone know what's wrong with it?

Thank you very much!

Upvotes: 2

Views: 4934

Answers (1)

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798546

'A' is a str. You want b'A', which is a bytes.

"Unicode In Python, Completely Demystified"

Upvotes: 2

Related Questions