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
标题: str.format() :n format does not appear to work for int and float
类型: behavior Stage:
Components: Interpreter Core Versions: Python 3.0, Python 2.6
process
状态: closed Resolution: fixed
Dependencies: 后续:
分配给: eric.smith 抄送列表: eric.smith, mark, nnorwitz
优先级: high 关键字:

Created on 2008-04-01 11:35 by mark, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (5)
msg64804 - (view) Author: Mark Summerfield (mark) * 日期: 2008-04-01 11:35
>>> # Py30a3
>>> import locale
>>> locale.setlocale(locale.LC_ALL, "en_US.UTF8")
'en_US.UTF8'
>>> locale.format("%d", 12345, True)
'12,345'
>>> "{0:n}".format(12345)
'12345'

According to the docs the 'n' format should use the locale-dependent
separator, so I expected both strings to be '12,345'.

Also, it is a pity that locale.format() uses the old deprecated % syntax
rather than the much nicer and better str.format() syntax.
msg64959 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) 日期: 2008-04-05 02:59
Eric, could you take a look?
msg64968 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) 日期: 2008-04-05 10:49
I'm looking into it.
msg64974 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) 日期: 2008-04-05 14:35
The same issue exists with floats:
# continuing the example

>>> locale.format("%g", 12345, True)
'12,345'
>>> "{0:n}".format(12345.0)
'12345'

The same issue exists in 2.6.
msg65988 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) 日期: 2008-04-30 01:10
Committed fix in r62586.
历史
日期 用户 动作 参数
2022-04-11 14:56:32admin修改github: 46778
2008-04-30 01:10:18eric.smith修改状态: open -> closed
resolution: fixed
消息: + msg65988
2008-04-05 14:35:32eric.smith修改标题: str.format() :n format does not appear to work -> str.format() :n format does not appear to work for int and float
消息: + msg64974
versions: + Python 2.6
2008-04-05 10:49:50eric.smith修改消息: + msg64968
2008-04-05 02:59:06nnorwitz修改优先级: high
assignee: eric.smith
消息: + msg64959
抄送: + eric.smith, nnorwitz
2008-04-01 11:35:24mark创建