DeprecationWarning: Non-ASCII character '\xc0'

A

ahsan Imam

Hello All,

I have this file and when I import the file in the python interpretor
I get the following error:

"__main__:1: DeprecationWarning: Non-ASCII character '\xc0' in file
trans.py on line 11, but no encoding declared; see
http://www.python.org/peps/pep-0263.html for details"

I am not sure what encoding to use. I am not sure where to look. I
picked one out of the documentation. Here is what I used:
# -*- coding: utf-8 -*-

Questions:
1) Is there a list I can pick the encoding from?
2) How can I find more about encoding?

Thanks, Ahsan
Here are contents of the file:
#!/usr/bin/python
"""This module defines various general purpose translations, such as
an upper ASCII to lower ASCII map.
"""
# -*- coding: utf-8 -*-
__revision__ = '$Id: trans.py,v 1.6 2001/10/25 17:43:49 estep Exp $'

UPPER_ASCII_MAP = {
'"':'"', '"' :'"',
'&':'&', '&' :'&',
'À':'A', '<\\\#203>':'A', '&Agrave;':'A', 'À':'A',
'Á':'A', '<\\\#231>':'A', '&Aacute;':'A', 'Á':'A',
'Â':'A', '<\\\#229>':'A', '&Acirc;' :'A', 'Â':'A',
'Ã':'A', '<\\\#204>':'A', '&Atilde;':'A', 'Ã':'A',
'Ä':'A', '<\\\#128>':'A', '&Auml;' :'A', 'Ä':'A',
'Å':'A', '<\\\#129>':'A', '&Aring;' :'A', 'Å':'A',
'Ç':'C', '<\\\#130>':'C', '&Ccedil;':'C', 'Ç':'C',
'È':'E', '<\\\#233>':'E', '&Egrave;':'E', 'È':'E',
'É':'E', '<\\\#131>':'E', '&Eacute;':'E', 'É':'E',
'Ê':'E', '<\\\#230>':'E', '&Ecirc;' :'E', 'Ê':'E',
'Ë':'E', '<\\\#232>':'E', '&Euml;' :'E', 'Ë':'E',
'Ì':'I', '<\\\#237>':'I', '&Igrave;':'I', 'Ì':'I',
'Í':'I', '<\\\#234>':'I', '&Iacute;':'I', 'Í':'I',
'Î':'I', '<\\\#235>':'I', '&Icirc;' :'I', 'Î':'I',
'Ï':'I', '<\\\#236>':'I', '&Iuml;' :'I', 'Ï':'I',
'Ñ':'N', '<\\\#132>':'N', '&Ntilde;':'N', 'Ñ':'N',
'Ò':'O', '<\\\#241>':'O', '&Ograve;':'O', 'Ò':'O',
'Ó':'O', '<\\\#238>':'O', '&Oacute;':'O', 'Ó':'O',
'Ô':'O', '<\\\#239>':'O', '&Ocirc;' :'O', 'Ô':'O',
'Õ':'O', '<\\\#205>':'O', '&Otilde;':'O', 'Õ':'O',
'Ö':'O', '<\\\#133>':'O', '&Ouml;' :'O', 'Õ':'O',
'Ø':'O', '<\\\#175>':'O', '&Oslash;':'O', 'Ø':'O',
'Ù':'U', '<\\\#244>':'U', '&Ugrave;':'U', 'Ù':'U',
'Ú':'U', '<\\\#242>':'U', '&Uacute;':'U', 'Ú':'U',
'Û':'U', '<\\\#243>':'U', '&Ucirc;' :'U', 'Û':'U',
'Ü':'U', '<\\\#134>':'U', '&Uuml;' :'U', 'Ü':'U',
'Ý':'Y', '&Yacute;':'Y', 'Ý':'Y',
'à':'a', '<\\\#136>':'a', '&agrave;':'a', 'à':'a',
'á':'a', '<\\\#135>':'a', '&aacute;':'a', 'á':'a',
'â':'a', '<\\\#137>':'a', '&acirc;' :'a', 'â':'a',
'ã':'a', '<\\\#139>':'a', '&atilde;':'a', 'ã':'a',
'ä':'a', '<\\\#138>':'a', '&auml;' :'a', 'ä':'a',
'å':'a', '<\\\#140>':'a', '&aring;' :'a', 'å':'a',
'ç':'c', '<\\\#141>':'c', '&ccedil;':'c', 'ç':'c',
'è':'e', '<\\\#143>':'e', '&egrave;':'e', 'è':'e',
'é':'e', '<\\\#142>':'e', '&eacute;':'e', 'é':'e',
'ê':'e', '<\\\#144>':'e', '&ecirc;' :'e', 'ê':'e',
'ë':'e', '<\\\#145>':'e', '&euml;' :'e', 'ë':'e',
'ì':'i', '<\\\#147>':'i', '&igrave;':'i', 'ì':'i',
'í':'i', '<\\\#146>':'i', '&iacute;':'i', 'í':'i',
'î':'i', '<\\\#148>':'i', '&icirc;' :'i', 'î':'i',
'ï':'i', '<\\\#149>':'i', '&iuml;' :'i', 'ï':'i',
'ñ':'n', '<\\\#150>':'n', '&ntilde;':'n', 'ñ':'n',
'ò':'o', '<\\\#152>':'o', '&ograve;':'o', 'ò':'o',
'ó':'o', '<\\\#151>':'o', '&oacute;':'o', 'ó':'o',
'ô':'o', '<\\\#153>':'o', '&ocirc;' :'o', 'ô':'o',
'õ':'o', '<\\\#155>':'o', '&otilde;':'o', 'õ':'o',
'ö':'o', '<\\\#154>':'o', '&ouml;' :'o', 'ö':'o',
'ø':'o', '<\\\#191>':'o', '&oslash;':'o', 'ø':'o',
'ù':'u', '<\\\#157>':'u', '&ugrave;':'u', 'ù':'u',
'ú':'u', '<\\\#156>':'u', '&uacute;':'u', 'ú':'u',
'û':'u', '<\\\#158>':'u', '&ucirc;' :'u', 'û':'u',
'ü':'u', '<\\\#159>':'u', '&uuml;' :'u', 'ü':'u',
'ý':'y', '&yacute;':'y', 'ý':'y',
'ÿ':'y', '<\\\#216>':'y', '&yuml;' :'y', 'ÿ':'y'}

entitydefs = {
'quot':'"',
'amp':'&',
'apos':''',
'lt':'<',
'gt':'>',
'Agrave':'À',
'Aacute':'Á',
'Acirc':'Â',
'Atilde':'Ã',
'Auml':'Ä',
'Aring':'Å',
'Ccedil':'Ç',
'Egrave':'È',
'Eacute':'É',
'Ecirc':'Ê',
'Euml':'Ë',
'Igrave':'Ì',
'Iacute':'Í',
'Icirc':'Î',
'Iuml':'Ï',
'Ntilde':'Ñ',
'Ograve':'Ò',
'Oacute':'Ó',
'Ocirc':'Ô',
'Otilde':'Õ',
'Ouml':'Ö',
'Oslash':'Ø',
'Ugrave':'Ù',
'Uacute':'Ú',
'Ucirc':'Û',
'Uuml':'Ü',
'Yacute':'Ý',
'agrave':'à',
'aacute':'á',
'acirc':'â',
'atilde':'ã',
'auml':'ä',
'aring':'å',
'ccedil':'ç',
'egrave':'è',
'eacute':'é',
'ecirc':'ê',
'euml':'ë',
'igrave':'ì',
'iacute':'í',
'icirc':'î',
'iuml':'ï',
'ntilde':'ñ',
'ograve':'ò',
'oacute':'ó',
'ocirc':'ô',
'otilde':'õ',
'ouml':'ö',
'oslash':'ø',
'ugrave':'ù',
'uacute':'ú',
'ucirc':'û',
'uuml':'ü',
'yacute':'ý',
'yuml':'ÿ',
}

entitydefs2 = {
'quot':'<\#34>',
'amp':'<\#38>',
'apos':'<\#39>',
'lt':'<\#60>',
'gt':'<\#62>',
'Agrave':'<\#192>',
'Aacute':'<\#193>',
'Acirc':'<\#194>',
'Atilde':'<\#195>',
'Auml':'<\#196>',
'Aring':'<\#197>',
'Ccedil':'<\#199>',
'Egrave':'<\#200>',
'Eacute':'<\#201>',
'Ecirc':'<\#202>',
'Euml':'<\#203>',
'Igrave':'<\#204>',
'Iacute':'<\#205>',
'Icirc':'<\#206>',
'Iuml':'<\#207>',
'Ntilde':'<\#209>',
'Ograve':'<\#210>',
'Oacute':'<\#211>',
'Ocirc':'<\#212>',
'Otilde':'<\#213>',
'Ouml':'<\#214>',
'Oslash':'<\#216>',
'Ugrave':'<\#217>',
'Uacute':'<\#218>',
'Ucirc':'<\#219>',
'Uuml':'<\#220>',
'Yacute':'<\#221>',
'agrave':'<\#224>',
'aacute':'<\#225>',
'acirc':'<\#226>',
'atilde':'<\#227>',
'auml':'<\#228>',
'aring':'<\#229>',
'ccedil':'<\#231>',
'egrave':'<\#232>',
'eacute':'<\#233>',
'ecirc':'<\#234>',
'euml':'<\#235>',
'igrave':'<\#236>',
'iacute':'<\#237>',
'icirc':'<\#238>',
'iuml':'<\#239>',
'ntilde':'<\#241>',
'ograve':'<\#242>',
'oacute':'<\#243>',
'ocirc':'<\#244>',
'otilde':'<\#245>',
'ouml':'<\#246>',
'oslash':'<\#248>',
'ugrave':'<\#249>',
'uacute':'<\#250>',
'ucirc':'<\#251>',
'uuml':'<\#252>',
'yacute':'<\#253>',
'yuml':'<\#255>',
}
 
S

Skip Montanaro

ahsan> "__main__:1: DeprecationWarning: Non-ASCII character '\xc0' in file
ahsan> trans.py on line 11, but no encoding declared; see
ahsan> http://www.python.org/peps/pep-0263.html for details"

ahsan> I am not sure what encoding to use. I am not sure where to look. I
ahsan> picked one out of the documentation. Here is what I used:
ahsan> # -*- coding: utf-8 -*-

Looks like the data you posted was encoded as iso-8859-1 (aka, latin-1), so
I suggest you use:

# -*- coding: iso-8859-1 -*-

as your coding comment.

ahsan> Questions:
ahsan> 1) Is there a list I can pick the encoding from?

Look at the filenames in the encodings package (part of the standard
distribution).

ahsan> 2) How can I find more about encoding?

Pick and choose from the results in found in these googlings:

http://www.google.com/search?q=encoding+site:www.python.org
http://www.google.com/search?q=unicode+site:www.python.org

Skip
 
?

=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=

ahsan said:
I am not sure what encoding to use. I am not sure where to look. I
picked one out of the documentation.

I recommend you avoid using non-ASCII characters in source code in
this specific case.
'À':'A', '<\\\#203>':'A', '&Agrave;':'A', 'À':'A',

Here, À is a non-ASCII character. If you copy-and-past this
to a Python session, and do
192

you find that it really is the character with the byte value
192. So reformulate the line above to

'À':'A', '<\\\#203>':'A', '&Agrave;':'A', chr(192):'A',

If you change all lines in this respect, you won't need an
encoding declaration anymore, as your source code is plain ASCII.

Regards,
Martin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,188
Latest member
Crypto TaxSoftware

Latest Threads

Top