args & kwargs

451 views
Skip to first unread message

Christopher.

unread,
Jun 1, 2016, 11:03:24 AM6/1/16
to Python Programming for Autodesk Maya
Hi, I understand what a non-keyword is, basically an argument, while a keyword is an variable inside and argument.  What I'm having trouble understanding is *args & *kwargs. I found this site but I'm still stuck. I'm not too familiar with loops at the moment so the example used on the site mentioned throws me a curve ball. 

I'm hoping someone can re-interpret how to use *args & **kwargs ?

yury nedelin

unread,
Jun 1, 2016, 12:00:32 PM6/1/16
to python_in...@googlegroups.com

Look at this site
http://www.saltycrane.com/blog/2008/01/how-to-use-args-and-kwargs-in-python/

I would say looking at more examples will help.
The way I understand it - if function accepts *args then you can pass any number of values(attributes, parameters) to it and then inside the function these values can be processed and used, if function accepts **kwargs then any number of key/value pairs can be passed to the function that can be processed and used.
In Maya python **kwargs pattern is used for passing MEL flags to python cmds version of the MEL command. For example cmds.ls(sl=true) - "sl=true" is a key/value pair passed to cmds.ls function that accepts **kwargs.

That's my understanding, please correct me if I am wrong.

Yury

On Jun 1, 2016 8:03 AM, "Christopher." <crestchr...@gmail.com> wrote:
Hi, I understand what a non-keyword is, basically an argument, while a keyword is an variable inside and argument.  What I'm having trouble understanding is *args & *kwargs. I found this site but I'm still stuck. I'm not too familiar with loops at the moment so the example used on the site mentioned throws me a curve ball. 

I'm hoping someone can re-interpret how to use *args & **kwargs ?

--
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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/159b1d5c-9ba3-49a4-b94b-09fc8089e088%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Crest Christopher

unread,
Jun 1, 2016, 1:14:04 PM6/1/16
to python_in...@googlegroups.com
yury - I did read that understanding args and kwargs may be a bit a of a hurdle. ;-) I'll go over the examples again, I got frustrated and posted hoping someone would explain with the perfect touch ;-)

That is not to say your touch is horrible, just a figure of speech !

Wednesday, June 01, 2016 12:00 PM

Look at this site
http://www.saltycrane.com/blog/2008/01/how-to-use-args-and-kwargs-in-python/

I would say looking at more examples will help.
The way I understand it - if function accepts *args then you can pass any number of values(attributes, parameters) to it and then inside the function these values can be processed and used, if function accepts **kwargs then any number of key/value pairs can be passed to the function that can be processed and used.
In Maya python **kwargs pattern is used for passing MEL flags to python cmds version of the MEL command. For example cmds.ls(sl=true) - "sl=true" is a key/value pair passed to cmds.ls function that accepts **kwargs.

That's my understanding, please correct me if I am wrong.

Yury

--
You received this message because you are subscribed to a topic in the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python_inside_maya/3nLxyS7OS6U/unsubscribe.
To unsubscribe from this group and all its topics, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CACqGScisHLKQc3CoNf5LhXdadRAMEvDM1%3DAk%3DkgKqskfQVwqrg%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.
Wednesday, June 01, 2016 11:03 AM
Hi, I understand what a non-keyword is, basically an argument, while a keyword is an variable inside and argument.  What I'm having trouble understanding is *args & *kwargs. I found this site but I'm still stuck. I'm not too familiar with loops at the moment so the example used on the site mentioned throws me a curve ball. 

I'm hoping someone can re-interpret how to use *args & **kwargs ?
--
You received this message because you are subscribed to a topic in the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python_inside_maya/3nLxyS7OS6U/unsubscribe.
To unsubscribe from this group and all its topics, send an email to python_inside_m...@googlegroups.com.

Rudi Hammad

unread,
Jun 4, 2016, 7:36:23 PM6/4/16
to Python Programming for Autodesk Maya
maybe this link could help

*args and **kwargs

this guys explain pretty good python


El miércoles, 1 de junio de 2016, 19:14:04 (UTC+2), Christopher. escribió:
yury - I did read that understanding args and kwargs may be a bit a of a hurdle. ;-) I'll go over the examples again, I got frustrated and posted hoping someone would explain with the perfect touch ;-)

That is not to say your touch is horrible, just a figure of speech !

Wednesday, June 01, 2016 12:00 PM

Look at this site
http://www.saltycrane.com/blog/2008/01/how-to-use-args-and-kwargs-in-python/

I would say looking at more examples will help.
The way I understand it - if function accepts *args then you can pass any number of values(attributes, parameters) to it and then inside the function these values can be processed and used, if function accepts **kwargs then any number of key/value pairs can be passed to the function that can be processed and used.
In Maya python **kwargs pattern is used for passing MEL flags to python cmds version of the MEL command. For example cmds.ls(sl=true) - "sl=true" is a key/value pair passed to cmds.ls function that accepts **kwargs.

That's my understanding, please correct me if I am wrong.

Yury

--
You received this message because you are subscribed to a topic in the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python_inside_maya/3nLxyS7OS6U/unsubscribe.
To unsubscribe from this group and all its topics, send an email to python_inside_maya+unsub...@googlegroups.com.
Wednesday, June 01, 2016 11:03 AM
Hi, I understand what a non-keyword is, basically an argument, while a keyword is an variable inside and argument.  What I'm having trouble understanding is *args & *kwargs. I found this site but I'm still stuck. I'm not too familiar with loops at the moment so the example used on the site mentioned throws me a curve ball. 

I'm hoping someone can re-interpret how to use *args & **kwargs ?
--
You received this message because you are subscribed to a topic in the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python_inside_maya/3nLxyS7OS6U/unsubscribe.
To unsubscribe from this group and all its topics, send an email to python_inside_maya+unsub...@googlegroups.com.

Cesar Saez

unread,
Jun 5, 2016, 10:55:10 AM6/5/16
to python_in...@googlegroups.com

On 2 Jun 2016 1:03 AM, "Christopher." <crestchr...@gmail.com> wrote:
>
> I'm hoping someone can re-interpret how to use *args & **kwargs ?

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

*args means the function/method accepts any number of arguments and those will be available as items of tuple named args.

*kwargs means the function/method accepts any number of keyword arguments and those will be available as items of dictionary named kwargs.

You can pick any name for the tuple/dict storing the arguments, it's just a local variable.

Hope this helps,
Cheers

Crest Christopher

unread,
Jun 5, 2016, 11:36:31 AM6/5/16
to python_in...@googlegroups.com
I think, I hope, I understand it by this point ;-)

Rudi or anyone else ;-)

In the video correct me if I'm wrong but he was debugging code within Sublime text ?

Cesar Saez wrote:

On 2 Jun 2016 1:03 AM, "Christopher." <crestchr...@gmail.com
<mailto:crestchr...@gmail.com>> wrote:
>
> I'm hoping someone can re-interpret how to use *args & **kwargs ?

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

*args means the function/method accepts any number of arguments and
those will be available as items of tuple named args.

*kwargs means the function/method accepts any number of keyword
arguments and those will be available as items of dictionary named
kwargs.

You can pick any name for the tupl e/dict storing the arguments, it's
just a local variable.

Hope this helps,
Cheers

--
You received this message because you are subscribed to a topic in the
Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/python_inside_maya/3nLxyS7OS6U/unsubscribe.
To unsubscribe from this group and all its topics, send an email to

To view this discussion on the web visit

Crest Christopher

unread,
Jun 5, 2016, 11:38:22 AM6/5/16
to python_in...@googlegroups.com
print('Ref1: %s'%id(process_all_textures));

Is taking the id and adding it to the string ? It can't be the math function modular because you can't modular a string with an id, correct ?

Sunday, June 05, 2016 10:55 AM
--
You received this message because you are subscribed to a topic in the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python_inside_maya/3nLxyS7OS6U/unsubscribe.
To unsubscribe from this group and all its topics, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPamJi9Rd_1fNN7sWrOf4dgO-Wo1R%3D%3DJYU03yLbuFAmdPGK%3D0g%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.
Wednesday, June 01, 2016 11:03 AM
Hi, I understand what a non-keyword is, basically an argument, while a keyword is an variable inside and argument.  What I'm having trouble understanding is *args & *kwargs. I found this site but I'm still stuck. I'm not too familiar with loops at the moment so the example used on the site mentioned throws me a curve ball. 

I'm hoping someone can re-interpret how to use *args & **kwargs ?
--
You received this message because you are subscribed to a topic in the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python_inside_maya/3nLxyS7OS6U/unsubscribe.
To unsubscribe from this group and all its topics, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/159b1d5c-9ba3-49a4-b94b-09fc8089e088%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages