Jul-10-2021, 05:15 PM
How can I convert a tuple to bytes ?
Tuple to bytes
|
Jul-10-2021, 05:15 PM
How can I convert a tuple to bytes ?
Jul-10-2021, 06:33 PM
Here is the example of the tuple below :
# define tuple for http header t_header = ( "Content-type: image/png \r", "Content-Language: pt-BR \r", ) b_header = bytearray(t_header, 'utf-8') print(type(b_header))Error msg : TypeError: encoding without a string argument ? Obs : I need the data type to be in bytes.
Jul-10-2021, 06:40 PM
t_header = ( "Content-type: image/png \r", "Content-Language: pt-BR \r", ) b_header = bytearray(str(t_header), 'utf-8') print(type(b_header))
Jul-10-2021, 08:48 PM
(This post was last modified: Jul-10-2021, 08:48 PM by deanhystad.)
Seems like a really odd thing to do. I would understand converting a string to byte array. What makes you think you need a tuple? As far as I know, tuples don't exist outside of Python.
|
|
Possibly Related Threads… | |||||
Thread | Author | Replies | Views | Last Post | |
code with no tuple gets : IndexError: tuple index out of range | Aggam | 4 | 4,298 |
Nov-04-2020, 11:26 AM Last Post: Aggam |
|
How to get first line of a tuple and the third item in its tuple. Need Help, Anybody? | SukhmeetSingh | 5 | 4,299 |
May-21-2019, 11:39 AM Last Post: avorane |
|
replace bytes with other byte or bytes | BigOldArt | 1 | 12,256 |
Feb-02-2019, 11:00 PM Last Post: snippsat |