User manual

x123 = 99 # OK
123x = 99 # not OK
Idenfiers 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)
funcon (introduced in SNAP version 2.5) to determine the type of any variable in SNAPpy. See the SNAP
Reference Manual for informaon on this built-in funcon.
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 funcons using “def
def sayHello():
print "hello"
sayHello() # calls the function, which prints the word “hello”
Funcons can take parameters
def adder(a, b):
print a + b
NOTE unlike Python, SNAPpy does not support oponal/default arguments. If a funcon takes two
parameters, you must provide two parameters. Providing more or fewer parameters gives an undefined
result. There are a few built-in SNAPpy funcons that do allow for oponal parameters, but user-defined
funcons must always be called with the number of parameters defined in the funcon signature.
It is also important in your Portal and SNAP Connect related programming to make sure that any rounes
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 funcon like…
8 SNAP® Network Operang System