Justus Perlwitz

You should get Packing with Python 3.5

The new Python 3.5 unpacking syntax makes a programmer’s life much easier.

Have you ever been in the following situation?

Now, if we want to reuse some_kwargs, they are tainted with the other kwargs. Of course, we could have constructed a new dict and used that to pass all the dict key-value pairs that we want to pass. But either way it feels messy.

The solution

Python 3.5 introduced PEP 0448 titled Additional Unpacking Generalizations. It allows you to do the following instead, assuming we’re using the same froblog method from above:

It outputs the same as above:

This is considerably cleaner. For more awesome unpacking madness, do check out the PEP 0448 document examples.

Happy unpacking!

Date created:
November 22, 2015

PDF version

Back to Index

You are more than welcome to share your thoughts via email