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 bug if thousand separator is space (french separator as example) #45563
Comments
locale.format function delete spaces in result which is a problem when The problem seems in the code below (extract from locale.py): 145 while seps: Example : >>> import locale
>>> locale.setlocale(locale.LC_NUMERIC)
'C'
>>> locale.setlocale(locale.LC_NUMERIC, "fr_FR.UTF-8")
'fr_FR.UTF-8'
>>> locale.format("%.2f", 12345.67, True)
'12345,67' The correct result is '12 345,67' not '12345,67' and if I call >>> locale.format("%9.2f", 12345.67, True)
'12 345,67' the result is correct Is this behavior correct or a bug? |
Just tried on 2.5.1 and on trunk, I can't reproduce it. On both I get: >>> import locale
>>> locale.setlocale(locale.LC_NUMERIC, "fr_FR.UTF-8")
'fr_FR.UTF-8'
>>> locale.format("%9.2f", 12345.67, True)
' 12345,67'
>>> locale.format("%.2f", 12345.67, True)
'12345,67'
>>> locale.localeconv()['thousands_sep']
'' Which means that there is no thousands separator for the French locale |
Ok, I manage to reproduce it on an Ubuntu box with both 2.5.2a0 and SVN |
Eric, your diagnostic looks right, format() gets confused when it tries Since Georg Brandl and Martin von Loewis are listed as co-authors, I add |
The space removal was there before my change; assigning to Martin. |
Here is a patch. It is fairly big and I'm sorry about it, here is why:
Point 2 above may be controversial, it is just a dictionary (by default |
Looks good to me. |
Here is an updated patch against trunk. |
I see that http://wiki.python.org/moin/PythonBugDay says "need to test |
I've had the opportunity to test on a Windows box and there are various |
Ok, here is an updated patch for Windows compatibility of the test suite. |
Would someone object to committing this before beta3? |
I'd recommend breaking the patch into the 3 parts mentioned in msg61929, |
The first 2 parts have been committed in r65237. I'll soon provide a |
Here is the patch for the third part. |
@antoine Pitrou Regarding "# XXX is the trailing space a bug?": I'm inclined to believe """ char *int_curr_symbol; /* First three chars are a currency symbol I haven't seen that fifth character, and in the libc sources I can't glibc-2.7/localedata/locales/nl_NL:66:int_curr_symbol I do however see a separator. In libc documentation I found here ( """ In other words, treat all nonzero values alike in these members. This is probably not right either, because this forces you to use an """ glibc-2.7/localedata/locales$ grep ^int_curr_symbol * | grep -vE That leaves us with two more options. Option three: the fourth character And finally, option four: international formatting should ignore all of Personally I would go with option three. It has the least impact on |
Committed in r70356, r70357, r70358, r70359. I didn't try to change |
r70357 seems to have caused the sparc solaris py3k buildbot to start failing on ====================================================================== Traceback (most recent call last):
File "/home2/buildbot/slave/3.x.loewis-sun/build/Lib/test/test_locale.py", line 181,
in test_integer_grouping_and_padding
out=('4%s200' % self.sep).rjust(10))
File "/home2/buildbot/slave/3.x.loewis-sun/build/Lib/test/test_locale.py", line 143,
in _test_format
func=locale.format, **format_opts)
File "/home2/buildbot/slave/3.x.loewis-sun/build/Lib/test/test_locale.py", line 139,
in _test_formatfunc
func(format, value, **format_opts), out)
AssertionError: ' 4200' != ' 4200' Any idea what's going on here? |
Hi Mark,
The problem seems to be that the thousands separator on the Solaris (*) (another reason not to use any C locale-based mechanism for |
By the way, Martin, do you have any idea why the Solaris buildbot |
Trying a fix in r70458. |
It looks like that did the trick. Thank you! |
Antoine Pitrou wrote:
I've come to believe this, too. I'm working on cleaning up the C |
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: