The subject shouldn't have said "Added". It's not a done deal! Eric. Eric Smith wrote:
I'd like to add a function (or method) to parse str.format()'s standard mini-language format specifiers. It's hard to get right, and if PEP 378 is accepted, it gets more complex.
The primary use case is for non-builtin numeric types that want to add __format__, and want it to support the same mini-language that the built in types support. For example see issue 2110, where Mark Dickinson implements his own version for Decimal, and suggests it be moved elsewhere.
This function exists in Objects/stringlib/formatter.h, and will just need to be exposed to Python code. I propose a function that takes a single str (or unicode) and returns a named tuple with the appropriate values filled in.
So, is such a function desirable, and if so, where would it go? I could expose it through the string module, which is where the sort-of-related Formatter class lives.
It could be a method on str and unicode, but I'm not sure that's most appropriate.
Eric. _______________________________________________ Python-ideas mailing list Python-ideas@python.org http://mail.python.org/mailman/listinfo/python-ideas