Have you considered including an encoding line at the top of your file, as
described in PEP 0263:
http://www.python.org/dev/peps/pep-0263/
I just ran into a similar error, but it went away when I included
# coding: utf-8
as the first line in my file.
--
http://mail.python.org/mailman/listinfo
On Aug 25, 6:34 am, Nobody wrote:
> The underlying OS primitive can only handle bytes. If you read or write a
> (unicode) string, Python needs to know which encoding is used. For Python
> file objects created by the user (via open() etc), you can specify the
> encoding; for those created by the ru
> 7stud (7) wrote:
>7> Thanks for the response. My OS is mac osx 10.4.11. I'm not really
>7> sure how to check my locale settings. Here is some stuff I tried:
>7> $ echo $LANG
>7> $ echo $LC_ALL
>7> $ echo $LC_CTYPE
>7> $ locale
>7> LANG=
>7> LC_COLLATE="C"
>7> LC_CTYPE="C"
>7> LC_MESS
On Tue, 25 Aug 2009 03:41:54 -0700, 7stud wrote:
> Why does echoing $LC_ALL or $LC_CTYPE just give me a blank string?
Because the variables aren't set.
The default locale for a particular category (e.g. LC_CTYPE) is taken from
$LC_ALL if that is set, otherwise $LC_CTYPE, otherwise $LANG, otherwi
On Aug 24, 10:09 pm, Ned Deily wrote:
> In article
> ,
>
>
>
> 7stud wrote:
> > On Aug 24, 2:41 pm, "Martin v. Löwis" wrote:
> > > > I can't figure out a way to programatically set the encoding for
> > > > sys.stdout. So where does that leave me?
>
> > > You should be setting the terminal enco
In article
,
7stud wrote:
> On Aug 24, 2:41 pm, "Martin v. Löwis" wrote:
> > > I can't figure out a way to programatically set the encoding for
> > > sys.stdout. So where does that leave me?
> >
> > You should be setting the terminal encoding administratively, not
> > programmatically.
> >
>
>
> > You should be setting the terminal encoding administratively, not
> > programmatically.
> >
>
> The terminal encoding has always been utf-8. It was not set
> programmatically.
>
> It seems to me that python 3.1's string handling is broken.
> Apparently, in python 3.1 I am unable to explicitl
On Aug 24, 2:41 pm, "Martin v. Löwis" wrote:
> > I can't figure out a way to programatically set the encoding for
> > sys.stdout. So where does that leave me?
>
> You should be setting the terminal encoding administratively, not
> programmatically.
>
The terminal encoding has always been utf-8.
> I can't figure out a way to programatically set the encoding for
> sys.stdout. So where does that leave me?
You should be setting the terminal encoding administratively, not
programmatically.
Regards,
Martin
--
http://mail.python.org/mailman/listinfo/python-list
On Aug 24, 12:19 pm, Stefan Behnel wrote:
> 7stud wrote:
> > python 3.1 won't let me
> > explicitly encode my unicode string
>
> Sure it does. But encoding a non-ASCII string to ASCII will necessarily fail.
>
As you should be able to see in the python 3.1 example I posted, I did
not encode the st
7stud wrote:
> python 3.1 won't let me
> explicitly encode my unicode string
Sure it does. But encoding a non-ASCII string to ASCII will necessarily fail.
> and python 3.1 implicitly does
> the encoding with the wrong codec.
That's not a Python problem, though. Your terminal is configured for
U
On Aug 24, 9:56 am, "Martin v. Löwis" wrote:
> > I don't understand why I'm getting an encode error in python 3.1.
>
> The default encoding is not relevant here at all. Look at
> sys.stdout.encoding.
>
> Regards,
> Martin
Hi,
Thanks for the response. I get US-ASCII for both 2.6 and 3.1:
===pyt
> I don't understand why I'm getting an encode error in python 3.1.
The default encoding is not relevant here at all. Look at
sys.stdout.encoding.
Regards,
Martin
--
http://mail.python.org/mailman/listinfo/python-list
==python 2.6 ==
import sys
print sys.getdefaultencoding()
s = u"\u20ac"
print s.encode("utf-8")
$ python2.6 1test.py
ascii
€
=python 3.1 ===
import sys
print(sys.getdefaultencoding())
s = "€"
print(s.encode("utf-8"))
print(s)
$ python3.1 1test.py
utf-8
b'\xe2\x82\xac'
Tra
14 matches
Mail list logo