1. Home
  2. Computing & Technology
  3. Python

How Python Processes Non-English RSS Feeds

From , former About.com Guide

5 of 5

Python Encodes Unicode

The encode method is one of Python's built-in functions for string handling. It is not part of the string module. The basic format of the program call is as follows:

x = y.encode("<encoding>")
The quotation marks around the encoding are required. In this case, string y has already been assigned and is now being assigned to x in an encoding. The encoding being used may be one of a myriad of encodings that Python can use; for the complete list, see the Python documentation.

In the case of 8-bit Unicode, we want to assign the value of body to output using a "utf-8" encoding. So, rewrite line 105 of the program to read as follows:

output = body.encode("utf-8")
Now, when the output is printed in the subsequent line, it will be in Unicode. This also enables the web browser to render it properly.



Other tutorials in this series:

Part 1 | 2 | 3 | 4 | 5
Get the Code!
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.