Setting Context to Node, Knob or Curve Object

I often need to run code from within a group or gizmo instead of the top level (so nuke.allNodes() would return all nodes in a group rather than the top level for instance).
For groups I used to doe the ol' future import thingy:

from __future__ import with_statement
with nuke.toNode( 'MyGroup' ):
	print nuke.allNodes()

runIn_01

However, this won't work with gizmos:
runIn_02 

Here you can use nuke.runIn() like so:

def getAllNodes():
    return nuke.allNodes()
print nuke.runIn( 'MyGizmo', 'getAllNodes()' )

runIn_03

This helps with commands like nuke.showInfo() that only ever operate on the current context. This will  show you a whole bunch of info about "MyGizmo::

nuke.runIn('MyGizmo', 'nuke.showInfo()')

The cool thing is that you can use the same method to get "inside" a knob or animation curve if you need to, then use nuke.thisKnob() etc. to reference the current "context object"