1

In Python 3 there are str and bytes types. To convert a bytes type into a str type, one would call the decode() method on an instance and vice versa. I am confused as to why this is, why is it not encode()? As I understand it, internally the actual bytes in memory are being encoded into an encoding (UTF-8 in Python's case).

Anand S Kumar
91.5k18 gold badges196 silver badges179 bronze badges
asked Jun 18, 2015 at 4:47
2

1 Answer 1

4

The bytes are the encoding. You need to decode them in order to get the text they encode. How Python encodes the text as bytes internally is... not your problem.

answered Jun 18, 2015 at 4:49
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.