Valentin Berlier writes:

 >     f"""
 >     Guest list ({len(people)} people):
 >     {person.name + '\n' for person in people}
 >     """

That's nice!  It's already (almost[1]) legal syntax, but it prints the
repr of the generator function.  This could work, though:

    f"""                                     
    Guest list ({len(people)} people):       
    {person.name + chr(10) for person in people:5.25i}
    """

with i for "iterate iterable".  (The iterable might need to be
parenthesized if it's a generator function.)  The width spec is
intended to be max_elems.per_elem_width.  I guess you could also
generalize it to something like

    f"""                                     
    Guest list ({len(people)} people):       
    {person.name, '>25s', chr(10), '' for person in people:i}
    """

where the 2d element of the tuple is a format spec to apply to each
element, the 3d is the separator and the 4th the terminator.  Or
perhaps those parameters belong in the syntax of the 'i' format code.

I saw your later post that suggests making this default.  We could
tell programmers to use !s or !r if they want to see things like

    <generator object <genexpr> at 0x100fde580>

Probably not, though, at least not if you want all iterables treated
this way.  Possibly this could be restricted to generators, especially
if you use the element format as tuple syntax I proposed above rather
than embed the element format spec in the overall generator spec.

Steve

Footnotes: 
[1]  Need to substitute 'chr(10)' for '\n' in an f-string.

_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/YG4JTKKQSJO2X3EQH7KJCJEGQ44OSXNC/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to