471,578 Members | 1,491 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,578 software developers and data experts.

DeprecationWarning: Non-ASCII character '\xc0'

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>',
}
Jul 18 '05 #1
2 4404

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=encod...www.python.org
http://www.google.com/search?q=unico...www.python.org

Skip

Jul 18 '05 #2
ahsan Imam wrote:
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
ord("")

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

Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.