Created
July 7, 2016 05:01
-
-
Save mpurdon/1f4fc63959791c93cf59399d57af47ec to your computer and use it in GitHub Desktop.
Given a string variable, and value variable pass them into a function as kwarg key and value
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
""" | |
Normally we call a function like so: | |
some_function(key=value) | |
But what if we want to dynamically set a key and value from variables? | |
What if we want the function to expect a variable number of kwargs? | |
""" | |
from __future__ import print_function | |
def print_properties(**kwargs): | |
for key, value in kwargs.items(): | |
print('{}: {}'.format(key, value)) | |
if __name__ == "__main__": | |
property = 'foo' | |
value = 'bar' | |
print_properties(**dict([(property, value)])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment