1

I tried to generate random string with

python3 -c 'import base64, os; print(base64.b64encode(os.urandom(24)))' 

The output is:

b'32randomstring' 

Is it possible to remove the b'' ?

2
  • 3
    Does this answer your question? Suppress/ print without b' prefix for bytes in Python 3 Commented May 26, 2020 at 10:20
  • Thank you for pointing it out. I appreciate it but I found it too complicated and went with Felk's ansswer python3 -c "import base64, os; print(base64.b64encode(os.urandom(24)).decode('ascii'))" Commented May 26, 2020 at 12:33

1 Answer 1

2

The b-prefix indicates that you are dealing with a byte string, which is basically just a sequence of bytes. to turn those into text, you need to apply some encoding.

Given that you used base64, all the produced bytes nicely map onto ascii anyway, and you can do something like this:

print(base64.b64encode(os.urandom(24)).decode("ascii")) 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.