[Python-ideas] Have a "j" format option for lists
David Mertz
mertz at gnosis.cx
Thu May 10 16:00:22 EDT 2018
-1 on idea. Far too many edge cases that can't be handled... Or absurd
complexity added to format mini-language if it tries to handle them (and
still fails).
On Thu, May 10, 2018, 3:57 PM Eric V. Smith <eric at trueblade.com> wrote:
> On 5/10/18 12:28 PM, Facundo Batista wrote:
> > 2018-05-10 10:34 GMT-03:00 Chris Angelico <rosuav at gmail.com>:
> >
> >>>
> >>> Ideally, it will handle *any* iterable.
> >>
> >> If it's to handle arbitrary iterables, it can't be the normal style of
> >> "take this string, pass it to the object's __format__ method, and let
> >> it interpret it". That's why I suggested a bang notation instead. We
> >> have some already:
> >
> > Yes, I think it fits better, as it's not just a formatting, it's more
> > an "operation"...
> >
> >> A "!j" flag
> >> could take an iterable, format each element using the given format,
> >> and then join them. The letter "j" makes good sense then, as it
> >
> > Where would you indicate the separator if we use the bang notation?
>
> You would have to wedge it in before the colon. Something like:
>
> f'{lst!j, :20}'
>
> But then you couldn't have a colon in the separator. And this would be
> our first conversion character to be more than a single character.
>
> I'm opposed to this proposal. Just call str.join(), or write a helper
> function or class (depending on what you're trying to do). It's not
> worth complicating what's already a complicated topic.
>
> Eric
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180510/eb0415e8/attachment.html>
More information about the Python-ideas
mailing list