Converting str to bytes in Python 3.0 via Methods
Thursday February 19, 2009
Given the significant difference between text and data in Python 3.0, you will not go far in programming against the 3.0 standard without being able to convert between them. One simple method of converting between
str and bytes is to use the methods available to each class. To encode str as bytes, use str.encode(). For bytes to str, use byte.decode(). See "Converting str to bytes via Methods" for more on how to use them and more on transitioning from 2.x to Python 3.0.