Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #45689
| From | Carlos Nepomuceno <carlosnepomuceno@outlook.com> |
|---|---|
| Subject | RE: PEP 378: Format Specifier for Thousands Separator |
| Date | 2013-05-21 23:22 +0300 |
| References | <519BD0D2.5080203@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1939.1369167746.3114.python-list@python.org> (permalink) |
----------------------------------------
> Date: Tue, 21 May 2013 14:53:54 -0500
> From: bahamutzero8825@gmail.com
> To: python-list@python.org
[...]
>>
> What myth? People should indeed be using .format(), but no one said % formatting was going away soon. Also, the suggested change to the docs
> wasn't made and the issue is closed. The current docs do not say that % formatting isn't going to be deprecated, but it does mention its
> caveats and suggests .format(). If you are trying to say that % formatting will never ever go away, then you are wrong. It is highly
> unlikely to go away in a 3.x release, but /may/ get phased out in Python 4.0.
I vote for keeping str.__mod__()!
Anyway, is it possible to overload str.__mod__() without deriving a class? I mean to have something like:
old_mod = str.__mod__
def new_mod(x):
global old_mod
try:
old_mod(x)
except ValueError, ex:
#catch ValueError: unsupported format character ',' (0x2c) at index 1
#process new '%,d' format here
return '{:,}'.format(x) #just to illustrate the behaviour. it would have it's own faster code
str.__mod__ = new_mod #this raises TypeError: can't set attributes of built-in/extension type 'str'
sys.stdout.write('num=%,d\n' % 1234567)
> --
> CPython 3.3.2 | Windows NT 6.2.9200 / FreeBSD 9.1
> --
> http://mail.python.org/mailman/listinfo/python-list
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
RE: PEP 378: Format Specifier for Thousands Separator Carlos Nepomuceno <carlosnepomuceno@outlook.com> - 2013-05-21 23:22 +0300
Re: PEP 378: Format Specifier for Thousands Separator Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-05-22 02:42 +0000
RE: PEP 378: Format Specifier for Thousands Separator Carlos Nepomuceno <carlosnepomuceno@outlook.com> - 2013-05-22 05:56 +0300
Re: PEP 378: Format Specifier for Thousands Separator Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-05-22 03:08 +0000
RE: PEP 378: Format Specifier for Thousands Separator Carlos Nepomuceno <carlosnepomuceno@outlook.com> - 2013-05-22 06:38 +0300
Re: PEP 378: Format Specifier for Thousands Separator 88888 Dihedral <dihedral88888@gmail.com> - 2013-05-22 00:14 -0700
Re: PEP 378: Format Specifier for Thousands Separator Ned Batchelder <ned@nedbatchelder.com> - 2013-05-22 07:25 -0400
RE: PEP 378: Format Specifier for Thousands Separator Carlos Nepomuceno <carlosnepomuceno@outlook.com> - 2013-05-22 14:52 +0300
csiph-web