Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > print u"\u0432": why is this so hard? UnciodeEncodeError

Reply
Thread Tools

print u"\u0432": why is this so hard? UnciodeEncodeError

 
 
=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=
Guest
Posts: n/a
 
      04-12-2004
Skip Montanaro wrote:
> Martin> I wonder how much would break if Python would assume the
> Martin> terminal encoding is UTF-8 on Darwin. Do people use different
> Martin> terminal encodings?
>
> I generally use xterm instead of Terminal.app. I think it's encoding is
> latin-1.


Not on OS X. Terminal.App is a software package completely different
from xterm. For one thing, xterm is for X11, whereas Terminal.App is
for Window Server (or whatever the name of the Apple GUI is).

It may be that Apple has changed the defaults at some time, but
atleast on my installation, the default encoding of Terminal.App for
all users is UTF-8.

Regards,
Martin

 
Reply With Quote
 
 
 
 
Michael Hudson
Guest
Posts: n/a
 
      04-12-2004
"Martin v. Löwis" <(E-Mail Removed)> writes:

> Skip Montanaro wrote:
> > Martin> I wonder how much would break if Python would assume the
> > Martin> terminal encoding is UTF-8 on Darwin. Do people use different
> > Martin> terminal encodings?
> > I generally use xterm instead of Terminal.app. I think it's
> > encoding is
> > latin-1.

>
> Not on OS X. Terminal.App is a software package completely different
> from xterm. For one thing, xterm is for X11, whereas Terminal.App is
> for Window Server (or whatever the name of the Apple GUI is).


I think Skip knows this

Cheers,
mwh

--
You can lead an idiot to knowledge but you cannot make him
think. You can, however, rectally insert the information,
printed on stone tablets, using a sharpened poker. -- Nicolai
-- http://home.xnet.com/~raven/Sysadmin/ASR.Quotes.html
 
Reply With Quote
 
 
 
 
Skip Montanaro
Guest
Posts: n/a
 
      04-13-2004

David> Now I'm curious -- how do you even find out it's a Terminal
David> window you're looking at, rather than say an xterm?

I just compared the output of "env" in both xterm and Terminal windows and
came up with these clues:

* TERM in an xterm is "xterm". In Terminal it's "vt100".

* In Terminal a TERM_PROGRAM environment variable is defined with a
value of "Apple_Terminal".

* The xterm also defines DISPLAY for obvious reasons.

Skip

 
Reply With Quote
 
Skip Montanaro
Guest
Posts: n/a
 
      04-13-2004

Skip> I generally use xterm instead of Terminal.app. I think it's
Skip> encoding is latin-1.

Martin> Not on OS X.

I run xterms under XDarwin. I don't think the default encoding is different
than xterms in any other X environment. If I execute

print u'\xed'.encode("latin-1")

in an xterm I get an accented "i". If I execute

print u'\xed'.encode("utf-8")

in a Terminal window I also get an accented "i".

Skip

 
Reply With Quote
 
=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=
Guest
Posts: n/a
 
      04-13-2004
Skip Montanaro wrote:
> Skip> I generally use xterm instead of Terminal.app. I think it's
> Skip> encoding is latin-1.
>
> Martin> Not on OS X.
>
> I run xterms under XDarwin.


Sorry, I completely misunderstood.

My apologies,
Martin

 
Reply With Quote
 
Scott Schwartz
Guest
Posts: n/a
 
      04-14-2004
Skip Montanaro <(E-Mail Removed)> writes:
> I run xterms under XDarwin. I don't think the default encoding is different
> than xterms in any other X environment. If I execute


These days you can invoke it as uxterm to force it into utf-8 mode.

 
Reply With Quote
 
Scott Schwartz
Guest
Posts: n/a
 
      04-14-2004
=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?= <(E-Mail Removed)> writes:
> > Why is Python not respecting my locale?

>
> It is: however, your locale only tells Python the encoding of your
> terminal, not the encoding of an arbitrary file you may write to.


That's not the usual interpretation of locale. It's not about
terminals, it's about everything, especially files.

 
Reply With Quote
 
David Eppstein
Guest
Posts: n/a
 
      04-14-2004
In article <(E-Mail Removed)>,
Scott Schwartz <"schwartz+@usenet "@bio.cse.psu.edu> wrote:

> > It is: however, your locale only tells Python the encoding of your
> > terminal, not the encoding of an arbitrary file you may write to.

>
> That's not the usual interpretation of locale. It's not about
> terminals, it's about everything, especially files.


Files should be in a format that specifies the encoding explicitly,
either within the file or as part of an external file format
specification. One should not have to hope that the locale of the
person using the file is the same as that of the person who created it.

(I realize locale also affects e.g. collation order, but the most
problems come from encoding mismatches.)

--
David Eppstein http://www.ics.uci.edu/~eppstein/
Univ. of California, Irvine, School of Information & Computer Science
 
Reply With Quote
 
=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=
Guest
Posts: n/a
 
      04-14-2004
Scott Schwartz wrote:
>>It is: however, your locale only tells Python the encoding of your
>>terminal, not the encoding of an arbitrary file you may write to.

>
>
> That's not the usual interpretation of locale. It's not about
> terminals, it's about everything, especially files.


At the application's choice, though. Python should not guess unless
it is likely that it is guessing right. For files, it is likely
guessing wrong - even for text files.

Regards,
Martin

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
print a vs print '%s' % a vs print '%f' a David Cournapeau Python 0 12-30-2008 03:19 AM
Problem - I want to print Current Output of Pdf file and should print once.I get print dialog box but it is not working keto Java 0 05-30-2007 11:27 AM
why why why why why Mr. SweatyFinger ASP .Net 4 12-21-2006 01:15 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
Unlarging the print to print using PDF file to print Bun Mui Computer Support 3 09-13-2004 03:15 AM



Advertisments