This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: locale.format question
Type: Stage:
Components: Library (Lib) Versions: Python 2.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: andrewma, georg.brandl, r.david.murray
Priority: normal Keywords:

Created on 2005-04-10 01:28 by andrewma, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (4)
msg24974 - (view) Author: Andrew Ma (andrewma) Date: 2005-04-10 01:28
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'
>>>

msg24975 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2005-04-10 05:51
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.
msg24976 - (view) Author: Andrew Ma (andrewma) Date: 2005-04-10 14:55
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. 
msg99864 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-02-22 22:56
The last comment set this issue to 'remind' in case someone wanted to fix it in the future...it's pretty much fixed now.  format_string was added in 2.5, and in 2.6 format only accepts a string containing just a format code.
History
Date User Action Args
2022-04-11 14:56:10adminsetgithub: 41833
2010-02-22 22:56:42r.david.murraysetresolution: remind -> fixed

messages: + msg99864
nosy: + r.david.murray
2005-04-10 01:28:42andrewmacreate