[Python-bugs-list] [ python-Bugs-783348 ] UNIX-locale and repr()
SourceForge.net
noreply@sourceforge.net
Tue, 05 Aug 2003 11:54:28 -0700
Bugs item #783348, was opened at 2003-08-05 00:55
Message generated for change (Comment added) made by bcannon
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=783348&group_id=5470
>Category: Python Library
Group: Python 2.1.2
Status: Open
Resolution: None
>Priority: 3
Submitted By: Joerg Linnenkohl (jolinnen)
Assigned to: Nobody/Anonymous (nobody)
Summary: UNIX-locale and repr()
Initial Comment:
Hi,
please look at this code snippet:
#!/usr/bin/python
import sys
import os
import random
import locale
locale.setlocale(locale.LC_ALL, 'de_DE@euro')
dp = locale.localeconv().get('decimal_point', '.')
# print "--->",locale.localeconv()
print "--->",dp
a = random.random()
b = repr(a)
print b
with this output :
---> ,
0.24851180874790457
I expect that the output of b must be "0,24851180874790457"
with a "," as a decimal point corresponding to the locale.
But for floating point numbers repr() always delivers the "."
as decimal point for the german locale.
The real problem occurs in the email package
(http://mimelib.sourceforge.net/) in the method :
def _make_boundary(text=None):
# Craft a random boundary. If text is given, ensure that the
chosen
# boundary doesn't appear in the text.
dp = locale.localeconv().get('decimal_point', '.')
boundary = ('=' * 15) + repr(random.random()).split(dp)[1] +
'=='
for the german locale (error 'listindex out of range') on
repr(random.random()).split(dp)[1].
Kind regards
Jörg Linnenkohl
----------------------------------------------------------------------
>Comment By: Brett Cannon (bcannon)
Date: 2003-08-05 11:54
Message:
Logged In: YES
user_id=357491
This is a known issue. Python requires that LC_NUMERIC for
locale settings *always* be set to the "C" locale. This is so that
numeric values stored in .pyc files can be converted with no issue
from their string representation to the proper Python object. This
was all recently discussed on python-dev; see the python-dev
Summary for July 2003 when it comes out (by the end of the
week) for a summary of the issue and discussion.
So the code in the email package is wrong for thinking repr will
return anything that uses something other than a period for a
decimal point. Since this is a 2.1.x issue (changed in 2.2.x
branch) I am lowering the priority on this. Or should this just be
closed?
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=783348&group_id=5470