[Python-ideas] Add a function to parse str.format() mini-language specifiers

Eric Smith eric at trueblade.com
Mon Mar 16 16:15:06 CET 2009


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 at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
> 




More information about the Python-ideas mailing list