From: bellman at lysator.liu.se (Thomas Bellman)
Date: 16 Apr 1999 16:40:46 GMT
Subject: Bug in Python 1.5.1 (with all patches) on Solaris 7?
References: <7f76eh$ijj@news2.newsguy.com>
Message-ID: <7f7p6e$mhj$1@newsy.ifm.liu.se>
Content-Length: 1425
X-UID: 677                                                  

"Fredrik Nehr" <frneh at wmdata.com> writes:

> I'm experience different behaivors when running the same instructions as
> script and interactively, the interactive behaivor is correct.

> Example:

> 603 ~ $ cat foo.py
> import string
> print string.lower('ABC123???')
> 604 ~ $ python foo.py
> abc123???
> 605 ~ $ python
> Python 1.5.1 (#1, Mar 22 1999, 17:07:44)  [GCC 2.8.1] on sunos5
> Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
> >>> import string
> >>> print string.lower('ABC123???')
> abc123???
> >>>

Your interactive Python probably has readline support, and you
have $LC_CTYPE set to iso_8859_1 or something.  Readline seems to
call setlocale(LC_CTYPE, "") or something when loaded, which
makes tolower(), toupper(), and so on, behaving according to your
locale settings.

If you want that behaviour even without readline, just do

    import locale
    locale.setlocale(locale.LC_CTYPE, "")

before doing your string manipulations.  Locale settings are
unfortunately global to the entire process, making it awkward to
process text in different languages in different parts of the
program. :-(

To return to the default behaviour, you should set your locale to
"C".


-- 
Thomas Bellman,   Lysator Computer Club,   Link?ping University,  Sweden
"This isn't right.  This isn't even wrong."  !  bellman @ lysator.liu.se
                         -- Wolfgang Pauli   !  Make Love -- Nicht Wahr!




