How to Convert Non-ASCII Characters in Python

Written by alexander gokhfeld
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Convert Non-ASCII Characters in Python
Python language represents non-ASCII characters by using Unicode. (Jupiterimages/ Images)

The American Standard Code for Information Interchange, or ASCII, encoding defines codes for English characters, punctuation marks and special symbols with the numeric values running from 0 to 127. When you want to read or store non-ASCII characters, such as characters in foreign alphabets or accented English letters, in the Python programming language, you must convert them to the closest visual equivalents of ASCII characters in Python supported encoding. By using Python's unicode function you can present non-ASCII characters in user applications.

Skill level:

Other People Are Reading

Things you need

  • Python IDLE 2.7.1

Show MoreHide


  1. 1

    Click "Start" in Windows and then click "Notepad" to open Notepad text editor.

  2. 2

    Add the following code in the open window:

    import sys


    raw = 'A'.decode('cp437')

    print raw


    txt = unicode('A', encoding='utf-8')

    print u'\00C1'.encode('cp437')

    print txt

  3. 3

    Click "File" and then click "Save.' Enter "" in the "File Name" box and click the "Save' button.

  4. 4

    Click "Start" in Windows, select "Python 2.7" and then click "IDLE (Python GUI)." Click "File", select "Open" and then double-click on the "" in the open window.

  5. 5

    Click "Run" and then click "Run Module" to decode non-ASCII "A" character in the "CP437" encoding to the "UTF-8" encoding.

Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.