简体   繁体   中英

Python: Passing parameters by name

Hi I was wondering how to implement this in python. Lets say for example you have a function with two parameters and both print out to console

def myFunc(varA, varB):
    print 'varA=', varA
    print 'varB=', varB

I have seen libraries (pymel being the one that comes to mind) where it allows you to specify the parameter you are parsing data too by name in no specific order. for example

myFunc(varB=12, varA = 'Tom')

I am not sure what I am missing as this doesn't seem to work when I try to declare my own functions inside or outside the maya environment.

Any clues would be wonderful, thank you in advanced.

That's normal Python behavior. If you're seeing errors then you're goofing up something else (eg missing a required parameter, trying to pass positional arguments by name, etc.).

>>> def func(foo, bar):
...   print foo, bar
... 
>>> func(bar='quux', foo=42)
42 quux

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM