1. Home
  2. Computing & Technology
  3. Python
Python Blog

From Al Lukaszewski, Former About.com Guide to Python

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.
Explore Python
About.com Special Features

The Best Web Trends of the Decade

A look back at the best innovations, ideas and technologies over the last 10 years, More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Python

©2009 About.com, a part of The New York Times Company.

All rights reserved.