On 11/14/2012 04:07 PM, Marilyn Davis wrote:
> <snip>
>
> Goodness!  I didn't expect it to be a Mac thing.
>
> So, on a Windows machine, running Python 2.6.6, sys.stdout.encoding is
> 'cp1252', yet the code runs fine.
>
> On Ubuntu with 2.7, it's 'UTF-8' and  it runs just fine.
>
> I find this most mysterious.
>
> Thank you for any help to get it running on my Mac.
>
>

To resolve something like this, I'd start searching the internet (and
especially the python.org site) for a string like:
     python  sys.stdout.encoding

https://drj11.wordpress.com/2007/05/14/python-how-is-sysstdoutencoding-chosen/

According to this page, the encoding is chosen by the environment variable:
     LC_CTYPE

set LC_CTYPE=en_GB.utf-8


I have no idea if that's correct, or always correct, but it could be
worth experimenting.  (Later note:  I think this affects more than just
the terminal, so I'd skip it)

In the meantime, you  posted a link to

http://hints.macworld.com/article.php?story=20100713130450549

which suggests two different environment variables:  PYTHONIOENCODING and 
LC-CTYPE


Looking at the python.org site is presumably more authoritative.  See

http://docs.python.org/2/whatsnew/2.6.html?highlight=pythonioencoding

which says """
The encoding used for standard input, output, and standard error can be 
specified by setting the PYTHONIOENCODING 
<http://docs.python.org/2/using/cmdline.html#envvar-PYTHONIOENCODING> 
environment variable before running the interpreter. The value should be a 
string in the form <encoding> or <encoding>:<errorhandler>. The /encoding/ part 
specifies the encoding’s name, e.g. utf-8 or latin-1; the optional 
/errorhandler/ part specifies what to do with characters that can’t be handled 
by the encoding, and should be one of “error”, “ignore”, or “replace”. 
(Contributed by Martin von Loewis.)"""


Also:  
http://docs.python.org/2/using/cmdline.html?highlight=pythonioencoding#PYTHONIOENCODING
 
<http://docs.python.org/2/using/cmdline.html?highlight=pythonioencoding#PYTHONIOENCODING>

Anyway, just realize that this does NOT change the terminal.  If it's not 
really utf-8, you'll sometimes get garbage characters. But at least you 
shouldn't get the encoding errors.

The *right* answer I figure would be to experiment to find out what the 
terminal on your Mac actually uses, and use that in your environment variable.


-- 

DaveA

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to