User manual
def displayStatus(msg1, msg2):
print msg1 + msg2
…but in your SNAPpy scripts you have RPC calls like…
rpc(PORTAL_ADDR, "displayStatus", 1, 2, 3) # <- too many parameters provided
…or…
rpc(PORTAL_ADDR, "displayStatus", 1) # <- too few parameters provided
…then you are going to see no output at all in Portal. Because the “signatures” do not match, Portal does not
invoke the
displayStatus() funcon at all.
You can change the calling SNAPpy script(s), or you can change the Portal script, but they must match.
Funcons can return values
def adder(a, b):
return a + b
print adder(1, 2) # would print out "3"
Funcons can do nothing
def placeHolder(a, b):
pass
Funcons cannot be empty
def placeHolder(a, b):
# ERROR! - you have to at least put a "pass" statement here
# It is not sufficient to just have comments
This is also true for any code block, as might be found in a while loop or a condional branch. Each code block
must contain at least a pass statement.
Variables at the top of your script (outside the scope of a funcon definion) are global.
x = 99 # this is a global variable
def sayHello():
print "x=", x
Variables within funcons are usually local…
x = 99 # this is a global variable
def showNumber():
x = 123 # this is a separate local variable
print x # prints 123
…unless you explicitly say you mean the global one
x = 99 # this is a global variable
def showGlobal():
print x # this shows the current value of global variable x
SNAP® Network Operang System 9