What is the equivalent of chr(x) for bytes in python 3?

MRAB python at mrabarnett.plus.com
Sat Dec 26 07:56:43 EST 2009


Baptiste Lepilleur wrote:
> Hi,
> I'm looking for the equivalent of the built-in chr(x) function that 
> would return a bytes type taking an integer as parameter.
> 
> The easiest way I found to do this is the function below, but there must 
> be some simpler way to do that and I must be overlooking something 
> fairly obvious...
> 
 >>> bytes([12])
b'\x0c'
 >>> bytes([1, 2, 3])
b'\x01\x02\x03'




More information about the Python-list mailing list