Unicode formatting for Strings

2007-02-05 Thread robson . cozendey . rj
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; see http://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

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unicode formatting for Strings

2007-02-05 Thread robson . cozendey . rj
On Feb 5, 7:00 pm, "Chris Mellon" <[EMAIL PROTECTED]> wrote:
> On 2/5/07, Kent Johnson <[EMAIL PROTECTED]> wrote:
>
>
>
>
>
> > [EMAIL PROTECTED] 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
>
> > It looks like you are saving the file in Unicode format (not utf-8) and
> > Python is choking on the Byte Order Mark that Notepad puts at the
> > beginning of the document.
>
> Notepad does support saving to UTF-8, and I was able to do this
> without the problem the OP was having. I also saved both with and
> without a BOM (in UTF-8) using SciTe, and Python worked correctly in
> both cases.
>
>
>
> > Try using an editor that will save utf-8 without a BOM, e.g. jedit or
> > TextPad.
>
> > Kent
> > --
> >http://mail.python.org/mailman/listinfo/python-list- Hide quoted text -
>
> - Show quoted text -- Hide quoted text -
>
> - Show quoted text -

I saved it in UTF-8 with Notepad. I was thinking here... It can be a
limitation of file.open() method? Have anyone tested that?

-- 
http://mail.python.org/mailman/listinfo/python-list