Maya Python: name not defined with floatSliderGrp
<p>I'm trying to get a scale slider steup, and whenever I change the slider value, I'd like for the new value to be printed out:</p>

<pre><code>    scaleSlider = cmds.floatSliderGrp(label='Curve Scale', 
                                  field=True, 
                                  minValue=0.0, 
                                  maxValue=2.0, 
                                  fieldMinValue=0.0, 
                                  fieldMaxValue=2.0, 
                                  value=1, 
                                  cc="print cmds.floatSliderGrp(scaleSlider, q=True, v=True)" )
</code></pre>

<p>This seems pretty simple, but I'm getting this error:</p>

<pre><code>// Error: name 'scaleSlider' is not defined
# Traceback (most recent call last):
#   File "&lt;maya console&gt;", line 1, in &lt;module&gt;
# NameError: name 'scaleSlider' is not defined //
</code></pre>

<p>The error is not very descriptive, unfortunately. I'm having trouble tracking down what the issue might be. At first I thought it was self-referential, but the error would tell me if so, correct?</p>

<p>Your problem is in the  <code>cc</code> argument. 
First, you've passed a <em>statement</em> not a function: you'd need to wrap the whole thing in a def or a lambda to work correctly.  Second, you're passing it a string reference to <code>scaleSlider</code>, but at the time the callback is defined that variable doesn't exist.  There are circumstances under which this code <em>would</em> work and others under which it won't (inside a function, for example, it will fail). Using string callback arguments is an invitation to these kinds of problems.  </p>

<p>It's easier to do it like this:</p>

<pre><code>w = cmds.window() 
c = cmds.columnLayout()
s = cmds.floatSliderGrp("example")

def callback(*_):
    print s, "=", cmds.floatSliderGrp(s, q=True, v=True)

cmds.floatSliderGrp(s, e=True, cc=callback)
cmds.showWindow(w)
</code></pre>

<p>Because <code>callback</code> is defined after <code>cmds.floatSliderGrp("example")</code> has executed, it knows the value of <code>s</code> (don't use single-letter variables in real code!) .  Because <code>cmds.floatSliderGrp(s, e=True, cc=callback)
</code> executes after that, it passes the version of the callback which knows the correct value of <code>s</code> to this particular float slider group.  This example will work in the listener or wrapped inside a function because the scoping is consistent.</p>

<p>@AriGold's solution will also work, although <code>lambdas</code> can't be used in a loop -- if you tried to run his solution in a loop all of the callbacks may end up pointing at the last UI element because lambda's bind very late.  </p>

<p>Lots more detail on the different ways to set up UI callbacks <a href="http://theodox.github.io/2014/maya_callbacks_cheat_sheet" rel="nofollow">here</a></p>

python user-interface maya