Specifications
Identifiers may only contain alphanumeric characters and underscores
x123_percent = 99 # OK
$%^ = 99 # not OK
There are several types of variables
a = True # Boolean
b = False # Boolean
c = 123 # Integer, range is -32768 to 32767
d = "hello" # String
e = (1, 2, 3) # Tuple
f = None # Python has a "None" data type
g = startup # Function
In the above example, invoking g() would be the same as directly calling startup().
String Variables can contain Binary Data
A = "\x00\xFF\xAA\x55" # The "\x" prefix means Hexadecimal
You define new functions using “def”
def sayHello():
print "hello"
sayHello() # prints the word “hello”
Functions can take parameters
def adder(a, b):
print a + b
NOTE – unlike Python, SNAPpy does not support optional/default arguments. If a function takes two
parameters, you must always provide two parameters.
It is also important in your Portal and SNAPconnect related programming to make sure that any
routines defined in Portal scripts (or SNAPconnect clients) accept the same number and type of
parameters that the remote callers are providing. For example:
If in a Portal script you define a function like…
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
Page 18 of 202 SNAP Reference Manual Document Number 600-0007K