千位分隔符怎么设置python,如何设置自定义千位分隔符?

I know that theoretically digits in large integers can be grouped by thousands for better readability:

Python 3.5.2 (default, Nov 17 2016, 17:05:23)

[GCC 5.4.0 20160609] on linux

Type "help", "copyright", "credits" or "license" for more information.

>>> import locale

>>> locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')

'en_US.UTF-8'

>>> locale.format('%d', 1234567890, grouping=True)

'1,234,567,890'

>>> "{:n}".format(1234567890)

'1,234,567,890'

However, surprisingly, this won’t work for every locale:

>>> locale.setlocale(locale.LC_ALL, 'pl_PL.UTF-8')

'pl_PL.UTF-8'

>>> locale.format('%d', 1234567890, grouping=True)

'1234567890'

>>> "{:n}".format(1234567890)

'1234567890'

Why are numbers not formatted? I find this strange. I would expect something like 1 234 567 890 being printed.

Per Format Specification Mini-Language, we can explicitly enforce two possible separators: a comma , and an underscore _. Sadly, a comma is inappropriate for Polish since it is used as a decimal point separator there, and a number like 1_234_567_890 would look oddly for most people.

Can we somehow enforce a non-breaking space being used as a thousands separator?

解决方案

The pl_PL locale thousands separator seems to be empty. I don't know if this accurately represents common usage in Poland, but Python is correctly formatting your number according to the rules of the pl_PL locale. This may be a bug in the locale files.

As far as I am aware, there is no option to manually specify the thousands separator and decimal mark characters.