[Python-Dev] transitioning from % to {} formatting

Steven Bethard steven.bethard at gmail.com
Wed Sep 30 17:39:14 CEST 2009

On Wed, Sep 30, 2009 at 8:31 AM, Barry Warsaw <barry at python.org> wrote:
> On Sep 30, 2009, at 11:22 AM, Steven Bethard wrote:
>> On Wed, Sep 30, 2009 at 5:21 AM, Barry Warsaw <barry at python.org> wrote:
>>> On Sep 29, 2009, at 11:15 PM, Martin v. Löwis wrote:
>>>> I would propose that the format argument gets an argument name,
>>>> according to the syntax it is written in. For PEP 3101 format,
>>>> I would call the argument "format" (like the method name of the
>>>> string type), i.e.
>>>> logging.Formatter(
>>>>  format="{asctime} - {name} - {levelname} - {message}")
>>>> For the % formatting, I suggest "dicttemplate" (assuming that
>>>> you *have* to use dictionary %(key)s style currently).
>> Could you comment on what you think we should do when the parameter is
>> not positional? As I mentioned upthread, in the case of
>> logging.Formatter, it's already documented as taking the keyword
>> parameter "fmt", so we'd have to use the name "fmt" for % formatting.
> I'm okay with fmt==%-formatting and format=={}-formatting, but I'd also be
> okay with transitioning 'fmt' to 'dicttemplate' or whatever.  I think the
> important thing is to be explicit in the method signature which one you want
> (secondary would be trying to standardize this across the stdlib).

Thanks for the clarification. I generally like this approach, though
it's not so convenient for argparse which already takes format strings
like this::

    parser = ArgumentParser(usage='%(prog)s [--foo]')
        '--foo', type=int, default=42,
        help='A foo of type %(type)s, defaulting to %(42)s)

That is, existing keyword arguments that already have good names (and
are pretty much always used as keyword arguments) take format strings.
I'm not sure that changing the name of usage= or help= here is really
an option.

I guess in this case I'm stuck with something like Benjamin's
suggestion of adding an additional flag to control which type of
formatting, and the corresponding 4 versions of cleanup. Ew.

Where did you get that preposterous hypothesis?
Did Steve tell you that?
        --- The Hiphopopotamus

More information about the Python-Dev mailing list