Python doesn't appear to have been enabled for expressions except for
as a way of running a TCL expression. In other words to do it the
Python way inside knob's expression field you'd end up having to write
a script to run in the script editor that would, in the end, set the
expression value to what you're already typing in.
I doubt that makes any sense at all, but Python seems to be there to
overcome scripting difficulties, like setting the values of nodes
recursively, or creating new nodes (or entire trees), or parsing text
files, etc., but it doesn't seem to replace the (arguably limited)
expression syntax within each node, which I guess make sense for
backwards compatibility purposes.
To use the sample directly in the Script Editor or a python script,
say in the context of building a tool that asked input from the user
and then returned the value (all of which could be used for a huge
range of purposes) you'd write a script sort of like this and run it
in the Script Editor.
nodetotest = nuke.selectedNode()
R = str(nuke.channels(nodetotest)[0])
G = str(nuke.channels(nodetotest)[1])
B = str(nuke.channels(nodetotest)[2])
chandict = {}
chandict['r'] = R
chandict['g'] = G
chandict['b'] = B
trychan = nuke.getInput("What channel? (enter r for Red, g for Green,
or b for Blue)")
tryx = int(nuke.getInput("What x pixel value? (must be an integer)"))
tryy = int(nuke.getInput("What y pixel value? (must be an integer)"))
trydx = int(nuke.getInput("How wide is the sample? (must be an integer
and NOT 0)"))
trydy = int(nuke.getInput("How tall is the sample? (must be an integer
and NOT 0)"))
nuke.display(str(nuke.sample(nodetotest, chandict[trychan], tryx,
tryy, trydx, trydy)),nodetotest,"Result")
Copy and paste that into the script editor window and run it, then
make sure you follow the directions, and you should see what I mean.
Michael M