By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,617 Members | 1,172 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,617 IT Pros & Developers. It's quick & easy.

DeprecationWarning: Non-ASCII character '\xf3'

P: n/a
jau
Hi co-listers!

I have been off Python for 2 years and now, that i'm used to Eclipse and
Java, I decided to start a project with Python to refresh skills this
time using Eclipse and TrueStudio. But now, two things can be occured
since the last time i used it.

the first one, something concerning to the encoding has changed and i
haven't noticed it.

the other one, when using Python from Eclipse i have to add any special
config lines at the begining of my Python files.

if i have this hello world python "program" (i have to call it by
someway, hahaha)

print "hello world"

i get this output

hello world
sys:1: DeprecationWarning: Non-ASCII character '\xf3' in file
C:\Workspace\J&J\src\es\jau\main.py on line 2, but no encoding declared;
see http://www.python.org/peps/pep-0263.html for details

the article mentioned above didn't explain so much for me.

i doesn't look to be an error, but curiosity is bitting me... what's
really happening here? Do I need to do any special thing to avoid this?

Thanks everyone!

Salut i república
Aug 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"jau" <ja************@airtel.net> wrote:
print "hello world"

i get this output

hello world
sys:1: DeprecationWarning: Non-ASCII character '\xf3' in file
C:\Workspace\J&J\src\es\jau\main.py on line 2, but no encoding declared;
see http://www.python.org/peps/pep-0263.html for details

the article mentioned above didn't explain so much for me.


the error message means that Python found an \xF3-character
on the second line in your main program (\xF3 is usually "latin
small letter o with acute", or "ó")

the document you were referred to says

Python will default to ASCII as standard encoding if no other
encoding hints are given.

(in other words, Python wants you to use plain ASCII in your source
code, unless otherwise specified).

and continues

To define a source code encoding, a magic comment must
be placed into the source files either as first or second
line in the file:

#!/usr/bin/python
# -*- coding: <encoding name> -*-

(in other words, if you want to keep using non-ASCII characters, you
need to add a line like

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

and make sure it's the first or second line in your script. if you didn't
mean to add it, just get rid of it and try again. if eclipse doesn't
display
the character, check the file using notepad or some other editor)

</F>

Aug 23 '05 #2

P: n/a
jau wrote:
Hi co-listers!

I have been off Python for 2 years and now, that i'm used to Eclipse and
Java, I decided to start a project with Python to refresh skills this
time using Eclipse and TrueStudio. But now, two things can be occured
since the last time i used it.

the first one, something concerning to the encoding has changed and i
haven't noticed it.

the other one, when using Python from Eclipse i have to add any special
config lines at the begining of my Python files.

if i have this hello world python "program" (i have to call it by
someway, hahaha)

print "hello world"

i get this output

hello world
sys:1: DeprecationWarning: Non-ASCII character '\xf3' in file
C:\Workspace\J&J\src\es\jau\main.py on line 2, but no encoding declared;
see http://www.python.org/peps/pep-0263.html for details

the article mentioned above didn't explain so much for me.

i doesn't look to be an error, but curiosity is bitting me... what's
really happening here? Do I need to do any special thing to avoid this?


The single print statement above should not trigger this warning. Are there
any non-ASCII character in the file (perhaps comments?).
If you use non-ASCII characters in python source files, you have to tell the
interpreter which encoding you are using - otherwise funny things will
happen. You have to find out which encoding Eclipse uses to save file
(looks like iso-8859-1) and add the line

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

at the top of the file.

Python does not make any assumptions about the encoding beyond US-ASCII
(perhaps it does, but it does not encourage taking advantage of this) - if
you use anything else, then you'll have to declare it.

This will be important, if you use unicode strings:

u"stränge characters"

Python must know the encoding of the file in order to decode the string
literal into an unicode string.

--
Benjamin Niemann
Email: pink at odahoda dot de
WWW: http://www.odahoda.de/
Aug 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.