[Python-ideas] Short form for keyword arguments and dicts
Ron Adam
ron3200 at gmail.com
Mon Jun 24 22:49:38 CEST 2013
On 06/24/2013 01:03 PM, Terry Reedy wrote:
>> While it looks a little magical, the proposed syntax would be an
>> improvement (especially when there are many arguments):
>>
>>>>> print('{spam} and {eggs}'.format(=spam, =eggs))
>
> It looks pretty hideous to me ;-).
> And it still has repetition ;-).
In larger programs, data like this would probably be in a dictionary or
some other structure.
There may be a large dictionary of many foods. And we would just use
.format_map and not have any repetition where those are used.
print('{spam} and {eggs}'.format_map(foods))
I think it would also be useful to get a sub_view of a dictionary.
breakfast = ['spam', 'eggs']
print('{spam} and {eggs}'.format_map(foods.sub_view(breakfast)))
The food dictionary might also have lunch items and dinner items in it, and
we don't want to serve dinner for breakfast by mistake. ;-)
Cheers,
Ron
More information about the Python-ideas
mailing list