Unicode formatting for Strings

kyosohma at gmail.com kyosohma at gmail.com
Mon Feb 5 14:10:33 EST 2007


On Feb 5, 11:55 am, robson.cozendey... at gmail.com wrote:
> Hi,
>
> I´m trying desperately to tell the interpreter to put an 'á' in my
> string, so here is the code snippet:
>
> # -*- coding: utf-8 -*-
> filename = u"Ataris Aquáticos #2.txt"
> f = open(filename, 'w')
>
> Then I save it with Windows Notepad, in the UTF-8 format. So:
>
> 1) I put the "magic comment" at the start of the file
> 2) I write u"" to specify my unicode string
> 3) I save it in the UTF-8 format
>
> And even so, I get an error!
>
>   File "Ataris Aqußticos #2.py", line 1
> SyntaxError: Non-ASCII character '\xff' in file Ataris Aqußticos #2.py
> on line 1
> , but no encoding declared; seehttp://www.python.org/peps/
> pep-0263.html for det
> ails
>
> I don´t know how to tell Python that it should use UTF-8, it keeps
> saying "no encoding declared" !
>
> Robson

I can't tell from your email if you get the message when you try to
open or close the file. So, I recommend that you read the following
article as it explains the whole unicode business quite well:
http://www.pyzine.com/Issue008/Section_Articles/article_Encodings.html




More information about the Python-list mailing list