Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mingrammer/916732cb51f4dcd0f678ffe56bf9a339 to your computer and use it in GitHub Desktop.
Save mingrammer/916732cb51f4dcd0f678ffe56bf9a339 to your computer and use it in GitHub Desktop.
headers = {
'Accept': 'text/plain',
'Content-Length': 348,
'Host': 'http://mingrammer.com'
}
def pre_process(**headers):
content_length = headers['Content-Length']
print('content length: ', content_length)
host = headers['Host']
if 'https' not in host:
raise ValueError('You must use SSL for http communication')
pre_process(**headers)
# content length: 348
# Traceback (most recent call last):
# File "<stdin>", line 1, in <module>
# File "<stdin>", line 7, in pre_process
# ValueError: You must use SSL for http communication
@hooy
Copy link

hooy commented Jul 18, 2018

This example is confusing and shows nothing about dict unpacking.
Shorter example like this is right usage of dict unpacking:

>>> def add(a=0, b=0):
...     return a + b
...
>>> d = {'a': 2, 'b': 3}
>>> add(**d)
5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment