Python Madlibs.py code and error message
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Thu Apr 28 03:25:32 EDT 2016
On Thursday 28 April 2016 17:08, Stephen Hansen wrote:
> On Wed, Apr 27, 2016, at 11:55 PM, Ben Finney wrote:
>> Stephen Hansen <me at ixokai.io> writes:
>>
>> > On Wed, Apr 27, 2016, at 10:32 PM, Ben Finney wrote:
>> > > Better: when you have many semantically-different values, use named
>> > > (not positional) parameters in the format string. […]
>> > >
>> > > <URL:https://docs.python.org/3/library/string.html#formatstrings>
>> >
>> > Except the poster is not using Python 3, so all of this is for naught.
>>
>> Everything I described above works fine in Python 2. Any still-supported
>> version has ‘str.format’.
>
> This response is completely unhelpful. The OP is using Python 2, and
> using %-formatting, and so you give a series of examples of using
> str.format, to, what? Confuse matters?
How about we assume good faith and give Ben the benefit of the doubt that he
simply made a minor and trivial misjudgement rather than accusing him of
intentionally trying to confuse matters?
You are correct that the OP can use % formatting with named arguments. Ben
is correct that the OP can also change his code to use str.format. Some
people hate %-formatting and cannot wait to migrate to {}-formatting, and
some people don't.
(For the record, Internet rumours that %-formatting is deprecated are simply
not correct.)
--
Steve
More information about the Python-list
mailing list