[Python-ideas] Short form for keyword arguments and dicts
Barry Warsaw
barry at python.org
Mon Jun 24 17:40:43 CEST 2013
On Jun 22, 2013, at 12:27 PM, Anders Hovmöller wrote:
>Keyword arguments are great for increasing readability and making code more
>robust but in my opinion they are underused compared to the gains they can
>provide. You often end up with code like:
>
>foo(bar=bar, baz=baz, foobaz=foobaz)
The DRY motivation for this proposal reminds me of PEP 292 ($-strings) and
flufl.i18n. In some of the earlier i18n work I did, the repetition was
overwhelmingly inconvenient. Generally, it doesn't bother me, but I really
hated doing things like:
real_name = get_real_name()
email_address = get_email_address()
message = _('Hi $real_name <$email_address>').safe_substitute(
real_name=real_name, email_address=email_address)
not to mention the high probability of typos, and the added noise making the
source harder to read. flufl.i18n then, shortens this to:
real_name = get_real_name()
email_address = get_email_address()
message = _('Hi $real_name <$email_address>')
The locals and globals are collected into the substitution dictionary, to be
applied after the source string is translated.
Yes, the implementation uses the dreaded sys._getframe(), but it's worth it.
http://tinyurl.com/kqy3hbz
http://tinyurl.com/lalxjaf
Cheers,
-Barry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130624/82160ba6/attachment-0001.pgp>
More information about the Python-ideas
mailing list