Problems Tackled!: Variable declaration in Maya Python's button command & # NameError: name 'function' is not defined #

The way of the sushi.py

def sushi():
    cmds.button(command = "var = funA(); funB()")
    cmds.button(command = funC(var))
    return

def funA():
    #stuff_makes_var
    return var

def funB():
     #more_stuff

def funC(var)
    #stuff_using_var 
                                                                            
                                                                              


The above is probably the most crazy syntax layout you will ever need when you make buttons in Maya Python.

Normally if you are in M.E.L  the syntax looks like:
button -command "functionA(); functionB()"
Which is already rare to see multiple commands being ran, but it can be done.

In Python you don't need the quotes so you get cmds.button(command = funcationA), but in this case you can't run multiple commands without declaring another function that includes all the functions you want to run, nor can you declare variables and pass it on to another button.
cmds.button(command = var = funA()) <-- Freestyle coding leads to errors.


It seems like when you use quotes, it calling the functions in them in the top scope instead of in the actual file, therefore even if you import sushi as su, and run su.sushi, it won't be able to run the functions in the quotes because it still doesn't exist in scope:
  # NameError: name 'function' is not defined # 

So to run it as a shelf button, you have to import the functions:

import sushi as su
reload(su)
from sushi import *  (or pick functions separately)
su.sushi()








 The noob days never end,
 D