User manual
x123 = 99 # OK
123x = 99 # not OK
Idenfiers may only contain alphanumeric characters and underscores
x123_percent = 99 # OK
x123% = 99 # not 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, size limits vary by platform
e = (1, 2, 3) # Tuple – usable only as a constant in SNAPpy
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(). You can use the type(arg)
funcon (introduced in SNAP version 2.5) to determine the type of any variable in SNAPpy. See the SNAP
Reference Manual for informaon on this built-in funcon.
String Variables can contain Binary Data
A = "\x00\xFF\xAA\x55" # The "\x" prefix means Hexadecimal character.
B = "Pi\xe1" # This creates a string of length 3
You define new funcons using “def”
def sayHello():
print "hello"
sayHello() # calls the function, which prints the word “hello”
Funcons can take parameters
def adder(a, b):
print a + b
NOTE – unlike Python, SNAPpy does not support oponal/default arguments. If a funcon takes two
parameters, you must provide two parameters. Providing more or fewer parameters gives an undefined
result. There are a few built-in SNAPpy funcons that do allow for oponal parameters, but user-defined
funcons must always be called with the number of parameters defined in the funcon signature.
It is also important in your Portal and SNAP Connect related programming to make sure that any rounes
defined in Portal scripts (or SNAP Connect 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 funcon like…
8 SNAP® Network Operang System