Locale bug?

=?ISO-8859-1?Q?Trond_Endrest=F8l?= Trond.Endrestol at ximalas.info
Tue Jan 3 09:08:33 EST 2012


Marko Rauhamaa <marko at pacujo.net> writes:

> Mysterious 8-bit characters appear in the string returned by strftime.
>
>     $ python
>     Python 2.7.2 (default, Oct 27 2011, 01:36:46) 
>     [GCC 4.6.1 20111003 (Red Hat 4.6.1-10)] on linux2
>     Type "help", "copyright", "credits" or "license" for more information.
>     >>> import time, locale
>     >>> locale.setlocale(locale.LC_TIME, ('fi_FI', 'UTF-8'))
>     'fi_FI.UTF-8'
>     >>> time.strftime("%a, %d %b %Y %H:%M:%S %z (%Z)")
>     'ti, 03 tammi\xc2\xa0 2012 14:52:47 +0200 (EET)'
>     >>> 
>     $ python3
>     Python 3.2.1 (default, Jul 11 2011, 18:55:33) 
>     [GCC 4.6.1 20110627 (Red Hat 4.6.1-1)] on linux2
>     Type "help", "copyright", "credits" or "license" for more information.
>     >>> import time, locale
>     >>> locale.setlocale(locale.LC_TIME, ('fi_FI', 'UTF-8'))
>     'fi_FI.UTF-8'
>     >>> time.strftime("%a, %d %b %Y %H:%M:%S %z (%Z)")
>     'ti, 03 tammi\xa0 2012 14:51:57 +0200 (EET)'
>     >>> 

It may be OS-specific. Your sample code runs fine on FreeBSD/i386
8.2-STABLE. The OS and Python 2.7.2 & 3.2.2 were recently compiled and
installed on my system.

    trond at enterprise:~>uname -sr
    FreeBSD 8.2-STABLE
    trond at enterprise:~>python
    Python 2.7.2 (default, Dec 20 2011, 08:49:23)
    [GCC 4.2.2 20070831 prerelease [FreeBSD]] on freebsd8
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import time, locale
    >>> locale.setlocale(locale.LC_TIME, ('fi_FI', 'UTF-8'))
    'fi_FI.UTF-8'
    >>> time.strftime("%a, %d %b %Y %H:%M:%S %z (%Z)")
    'Ti, 03 Tam 2012 15:02:32 +0100 (CET)'
    >>>
    trond at enterprise:~>python3.2
    Python 3.2.2 (default, Dec 21 2011, 14:42:29)
    [GCC 4.2.2 20070831 prerelease [FreeBSD]] on freebsd8
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import time, locale
    >>> locale.setlocale(locale.LC_TIME, ('fi_FI', 'UTF-8'))
    'fi_FI.UTF-8'
    >>> time.strftime("%a, %d %b %Y %H:%M:%S %z (%Z)")
    'Ti, 03 Tam 2012 15:03:15 +0100 (CET)'
    >>>
    trond at enterprise:~>

-- 
----------------------------------------------------------------------
Trond Endrestøl
ACM, NAS, NUUG, SAGE, USENIX



More information about the Python-list mailing list