If you use Python, I’d highly recommend joining realpython.com just for the emails. They include all sorts of tips that I personally would never uncover otherwise.

Here’s a good one from today’s email. You can force a function’s arguments (args, which can be passed without a key) to be keyword arguments (kwargs, which must be passed in the format key=value). So for example:

>>> def func(a, *, b, c):
...     print(a)
...     print(b)
...     print(c)
>>> func(1,2,3)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: func() takes 1 positional argument but 3 were given
>>> fu(1,b=2,c=3)

Pretty neat.

Tagged with:

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Set your Twitter account name in your settings to use the TwitterBar Section.