Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

locale.format question #41833

Closed
andrewma mannequin opened this issue Apr 10, 2005 · 4 comments
Closed

locale.format question #41833

andrewma mannequin opened this issue Apr 10, 2005 · 4 comments
Labels
stdlib Python modules in the Lib dir

Comments

@andrewma
Copy link
Mannequin

andrewma mannequin commented Apr 10, 2005

BPO 1180002
Nosy @birkenfeld, @bitdancer

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2010-02-22.22:56:42.741>
created_at = <Date 2005-04-10.01:28:42.000>
labels = ['library']
title = 'locale.format question'
updated_at = <Date 2010-02-22.22:56:42.741>
user = 'https://bugs.python.org/andrewma'

bugs.python.org fields:

activity = <Date 2010-02-22.22:56:42.741>
actor = 'r.david.murray'
assignee = 'none'
closed = True
closed_date = None
closer = None
components = ['Library (Lib)']
creation = <Date 2005-04-10.01:28:42.000>
creator = 'andrewma'
dependencies = []
files = []
hgrepos = []
issue_num = 1180002
keywords = []
message_count = 4.0
messages = ['24974', '24975', '24976', '99864']
nosy_count = 3.0
nosy_names = ['georg.brandl', 'andrewma', 'r.david.murray']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = None
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue1180002'
versions = ['Python 2.4']

@andrewma
Copy link
Mannequin Author

andrewma mannequin commented Apr 10, 2005

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'
>>>

@andrewma andrewma mannequin closed this as completed Apr 10, 2005
@andrewma andrewma mannequin added the stdlib Python modules in the Lib dir label Apr 10, 2005
@andrewma andrewma mannequin closed this as completed Apr 10, 2005
@andrewma andrewma mannequin added the stdlib Python modules in the Lib dir label Apr 10, 2005
@birkenfeld
Copy link
Member

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.

@andrewma
Copy link
Mannequin Author

andrewma mannequin commented Apr 10, 2005

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.

@bitdancer
Copy link
Member

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.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir
Projects
None yet
Development

No branches or pull requests

2 participants