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

From Al Lukaszewski, Former About.com Guide to Python

Converting bytes to str in Python 3.0 via Functions

Thursday February 26, 2009
Last week, we looked at how to convert between strings of the str data type and strings of the bytes data type using methods in the string class of Python 3.x. Another way that is a bit more straightforward is to simply call the function form of the target data type. So, to convert to str, call
str(<bytes string>, <encoding>)
Similarly, you can make bytes from str with
bytes(<str string>, <encoding>)
For more on the syntax of each, see "Converting str to bytes via Functions" in "A Guide to Text vs Data in Python 3.0".
Explore Python
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. 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.