[Python-3000] easy int to bytes conversion similar to chr?

"Martin v. Löwis" martin at v.loewis.de
Thu Aug 23 09:27:37 CEST 2007


Gregory P. Smith schrieb:
> Is there anything similar to chr(65) for creating a single byte string
> that doesn't involve creating an intermediate string or tuple object?
> 
>  bytes(chr(65))
>  bytes((65,))
> 
> both seem slightly weird.

b = bytes(1)
b[0] = 65

doesn't create an intermediate string or tuple object.

Regards,
Martin


More information about the Python-3000 mailing list