Hello,
It is sometimes tedious to write a dictionary in Python. For example,
def register_user(first, last, addr1, addr2):
d = {'first': first,
'last': last,
'addr1': addr1,
'addr2': addr2,
'tel': '123-456-789'}
requests.post(URL, d)
The dict literal contains a lot of duplicated words and quotation
marks. Using dict type looks nicer, but still verbose.
d = dict(first=first,
last=last,
addr1=addr1,
addr2=addr2,
tel='123-456-789')
With recent JavaScript, the same object can be written more easily.
d = {first, last, addr1, addr2, tel='123-456-789'}
How about adding similar syntax to Python? Like raw strings, we can
add prefix letters such as '$' to the opening curly brace for the
purpose.
d = ${first, last, addr1, addr2, tel='123-456-789'}
Keys should be valid identifier strings. Other keys raise SyntaxError.
I wrote a simple POC implementation here. It looks working.
https://github.com/atsuoishimoto/cpython/pull/2
(I prefer to use `j` for the prefix over `$`, but I may need to study
the parser more to use an ASCII letter as token.)
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/2UHZWIMHO5GIW7YD3ZT7WLGPVL2LFSK6/
Code of Conduct: http://python.org/psf/codeofconduct/