Bug in Python 1.5.1 (with all patches) on Solaris 7?

Thomas Bellman bellman at lysator.liu.se
Fri Apr 16 12:40:46 EDT 1999


"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!




More information about the Python-list mailing list