[Python-ideas] Have a "j" format option for lists

Antoine Pitrou solipsis at pitrou.net
Wed Jun 27 05:20:35 EDT 2018


On Wed, 9 May 2018 09:39:08 -0300
Facundo Batista
<facundobatista at gmail.com> wrote:
> This way, I could do:
> 
> >>> authors = ["John", "Mary", "Estela"]
> >>> "Authors: {:, j}".format(authors)  
> 'Authors: John, Mary, Estela'
> 
> In this case the join can be made in the format yes, but this proposal
> would be very useful when the info to format comes inside a structure
> together with other stuff, like...
> 
> >>> info = {  
> ...   'title': "A book",
> ...   'price': Decimal("2.34"),
> ...   'authors: ["John", "Mary", "Estela"],
> ... }
> ...
> >>> print("{title!r} (${price}) by {authors:, j}".format(**info))  
> "A book" ($2.34) by John, Mary, Estela
> 
> What do you think?

-1.  I hate that the format language is slowly becoming more and more
crufty, leading to unreadable code.

Yes, typing `", ".join(...)` is more work, but at least the end result
is readable.

Regards

Antoine.




More information about the Python-ideas mailing list