Re: Spanish Accents

2011-12-22 Thread Stan Iverson
On Thu, Dec 22, 2011 at 2:17 PM, Peter Otten <__pete...@web.de> wrote: > You are now one step further, you have successfully* decoded the file. > The remaining step is to encode the resulting unicode lines back into > bytes. > The encoding implicitly used by the print statement is sys.stdout.encod

Re: Spanish Accents

2011-12-22 Thread Peter Otten
Stan Iverson wrote: > On Thu, Dec 22, 2011 at 12:42 PM, Peter Otten <__pete...@web.de> wrote: > >> The file is probably encoded in ISO-8859-1, ISO-8859-15, or cp1252 then: >> >> >>> print "\xe1".decode("iso-8859-1") >> á >> >>> print "\xe1".decode("iso-8859-15") >> á >> >>> print "\xe1".decode("c

Re: Spanish Accents

2011-12-22 Thread Stan Iverson
On Thu, Dec 22, 2011 at 12:42 PM, Peter Otten <__pete...@web.de> wrote: > The file is probably encoded in ISO-8859-1, ISO-8859-15, or cp1252 then: > > >>> print "\xe1".decode("iso-8859-1") > á > >>> print "\xe1".decode("iso-8859-15") > á > >>> print "\xe1".decode("cp1252") > á > > Try codecs.open(

Re: Spanish Accents

2011-12-22 Thread Peter Otten
Stan Iverson wrote: > On Thu, Dec 22, 2011 at 11:30 AM, Rami Chowdhury > wrote: > >> Could you try using the 'open' function from the 'codecs' module? >> > > I believe this is what you meant: > > file = codecs.open(p + "2.txt", "r", "utf-8") > for line in file: > print line > > but got this

Re: Spanish Accents

2011-12-22 Thread Chris Angelico
On Fri, Dec 23, 2011 at 3:22 AM, Stan Iverson wrote: > > On Thu, Dec 22, 2011 at 11:30 AM, Rami Chowdhury > wrote: >> >> Could you try using the 'open' function from the 'codecs' module? > > I believe this is what you meant: > > file = codecs.open(p + "2.txt", "r", "utf-8") > > but got this erro

Re: Spanish Accents

2011-12-22 Thread Stan Iverson
On Thu, Dec 22, 2011 at 11:30 AM, Rami Chowdhury wrote: > Could you try using the 'open' function from the 'codecs' module? > I believe this is what you meant: file = codecs.open(p + "2.txt", "r", "utf-8") for line in file: print line but got this error: 141 file = codecs.open(p + "2.txt",

Re: Spanish Accents

2011-12-22 Thread Rami Chowdhury
On Thu, Dec 22, 2011 at 15:25, Stan Iverson wrote: > On Thu, Dec 22, 2011 at 10:58 AM, Chris Angelico wrote: > >> Firstly, are you using Python 2 or Python 3? Things will be slightly >> different, since the default 'str' object in Py3 is Unicode. >> > > 2 > >> >> I would guess that your page is

Re: Spanish Accents

2011-12-22 Thread Stan Iverson
On Thu, Dec 22, 2011 at 10:58 AM, Chris Angelico wrote: > Firstly, are you using Python 2 or Python 3? Things will be slightly > different, since the default 'str' object in Py3 is Unicode. > 2 > > I would guess that your page is being output as UTF-8; you may find > that the solution is as eas

Re: Spanish Accents

2011-12-22 Thread Chris Angelico
On Fri, Dec 23, 2011 at 1:55 AM, Stan Iverson wrote: > Hi; > If I write a python page to print to the web with Spanish accents all is > well. However, if I read the data from a text file it prints diamonds with > question marks wherever there are accented vowels. Please advise. So

Spanish Accents

2011-12-22 Thread Stan Iverson
Hi; If I write a python page to print to the web with Spanish accents all is well. However, if I read the data from a text file it prints diamonds with question marks wherever there are accented vowels. Please advise. TIA, Stan -- http://mail.python.org/mailman/listinfo/python-list