In my Java code I have the following snippet :
String secret = "secret";
byte[] thebytes = secret.getBytes();
I would like to have exactly the same result in python. How can I do that ?
secret = 'secret'
thebytes = ??? ??? ???
Thanks.
EDIT:
In addition, it will be interesting to have the solution for Python 2.x and 3.x
This is not as simple as it might first seem, because Python has historically conflated byte arrays and strings. The short answer, in Python 3, is
But you should read up on how Python deals with unicode, strings and bytes.