Skip to content

Instantly share code, notes, and snippets.

@mpurdon
Created July 7, 2016 05:01
Show Gist options
  • Save mpurdon/1f4fc63959791c93cf59399d57af47ec to your computer and use it in GitHub Desktop.
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
# -*- 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