[ python-Bugs-1180002 ] locale.format question
SourceForge.net
noreply at sourceforge.net
Sun Apr 10 16:55:35 CEST 2005
Bugs item #1180002, was opened at 2005-04-10 01:28
Message generated for change (Comment added) made by andrewma
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1180002&group_id=5470
Category: Python Library
Group: Python 2.4
>Status: Closed
>Resolution: Remind
Priority: 5
Submitted By: Andrew Ma (andrewma)
Assigned to: Nobody/Anonymous (nobody)
Summary: locale.format question
Initial Comment:
locale.format is returning send("234,5") rather than send
("2,345") as I was expecting. Is this a bug?
The example is modified from the Tutorial 11.1 Output
Formatting
--------------------------------------------------------------------------
Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310
32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more
information.
>>> import locale
>>> locale.setlocale(locale.LC_ALL, 'English_United
States.1252')
'English_United States.1252'
>>> data=2345
>>> locale.format('send("%d")', data, grouping = True)
'send("234,5")'
>>> locale.format('%d', data, grouping = True)
'2,345'
>>>
----------------------------------------------------------------------
>Comment By: Andrew Ma (andrewma)
Date: 2005-04-10 14:55
Message:
Logged In: YES
user_id=621709
Berk,
I followed your advice using
'send("%s")' % locale.format("%d", data, grouping=True)
and solved my problem. Too bad there is no way to add your
advice to the Python documentation. I am putting the status
to remind, in case anybody (including me) wants to fix this
later.
Thanks.
----------------------------------------------------------------------
Comment By: Reinhold Birkenfeld (birkenfeld)
Date: 2005-04-10 05:51
Message:
Logged In: YES
user_id=1188172
locale.format is implemented very "pragmatic". For example,
you can't do
locale.format('"1.%d."', 123)
("too many decimal points") though this should be supported.
This is because it first formats the string with the normal
"%" operation and then searches the whole string for decimal
points to substitute.
IMHO, format should first separate the % escapes from the
format string, then format the numbers accordingly, and then
use the % operation.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1180002&group_id=5470
More information about the Python-bugs-list
mailing list