On Wed, Mar 15, 2017, 5:12 AM likage <[email protected]> wrote:
> Try wrapping it in a lambda?
> self.btn_add = cmds.symbolButton( width=60, height=20, annotation='Add
> object(s)', image='add.xpm', command=lambda *x: self.add_btn_callback(
> "item_list") )
>
>
> Okay, so it works. And my question is why?
>
Python has a concept called "first class functions". It means a function is
an object just like anything else, like strings and lists. They can be
passed around as args and saved as references in variables. Callbacks are
implemented by have a function passed as an object so that the function can
be saved and called later.
def hello():
print "hello"
# call function immediately
hello()
# assign function to variable
fn = hello
fn()
Note that if you don't return a value from a function, the return value is
implicitly None. This will explain strange errors about the type when you
call the function instead of passing it as a first class function.
val = hello()
print type(val)
For more information here is a tutorial and a general wiki:
https://newcircle.com/bookshelf/python_fundamentals_tutorial/functional_programming
https://en.m.wikipedia.org/wiki/First-class_function
Justin
--
> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/4f0ec7aa-064a-415d-a295-0a1de7f6e430%40googlegroups.com
> <https://groups.google.com/d/msgid/python_inside_maya/4f0ec7aa-064a-415d-a295-0a1de7f6e430%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA3h1o%2B%3DikvnEwry0Gerr%3Do1scgKQnMaHkN%2Bf2u-u1sZnw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.