pass a diccionary as function parameters

22 views
Skip to first unread message

Rudi Hammad

unread,
May 4, 2017, 7:21:36 AM5/4/17
to Python Programming for Autodesk Maya
Hi,
 I am trying to do the following
Let´s say that I have a dictionary like this

myDic = {'config_type': u'high', 'config_path': u'C:\somePath'}

I want to create a function that will execute the following the dictionary items as parameters

def foo('config_type'= 'high', 'config_path': 'C:\somePath')

I can´t figure out how to do this.
myDic will keep changing all the time, and I want to extract each time the items as parameters and execute the function
as explained above. The examples that I´ve read with **kwargs I am not sure if they apply here.

thank you


Marcus Ottosson

unread,
May 4, 2017, 7:31:49 AM5/4/17
to python_in...@googlegroups.com

Try this.

myDic = {'config_type': u'high', 'config_path': u'C:\somePath'}

def foo(config_type='high', config_path='C:\somePath'):
    print(config_type, config_path)

foo(**myDic)
# Result: (u'high', u'C:\\somePath')

def foo(**kwargs):
    print(kwargs)

foo(**myDic)
# Result: {'config_type': u'high', 'config_path': u'C:\\somePath'}

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/30e22783-2e38-404e-8243-50a8d8126be2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Rudi Hammad

unread,
May 4, 2017, 7:32:48 AM5/4/17
to Python Programming for Autodesk Maya

I want to create a function that will execute the following the dictionary items as parameters

def foo('config_type'= 'high', 'config_path': 'C:\somePath')

EDIT: Sorry I meant def foo(config_type= 'high', config_path= 'C:\somePath')

Rudi Hammad

unread,
May 4, 2017, 8:21:22 AM5/4/17
to Python Programming for Autodesk Maya
Yes that´s it.Sorry, I misunderstood the use of **kwargs.
Thanks.
Reply all
Reply to author
Forward
0 new messages