User manual

Subscripng
Subscripng is supported for string and tuple data types. For example, if x = ('A', 'B', 'C') then x[1] = 'B'.
NOTE Prior to version 2.2, there was only a single “string buffer” for each type of string operaon
(slicing, concatenaon, subscripng, etc.). Subsequent operaons of that same type would overwrite
previous results. Version 2.2 replaces the fixed string buffers with a small pool of string buffers, usable for
any operaon. This allows scripts like the following to now work correctly:
A = B + C # for this example, all variables are strings
D = E + F
Scripts that do string manipulaons that were wrien to work within the 2.0/2.1 restricons will sll work as-is.
They just may be performing extra steps that are no longer needed with version 2.2 and above.
Expressions
SNAPpy supports all Python Boolean, binary bit-wise, shiing, arithmec, and comparison expressions
including the ternary if form.
x = +1 if a > b else -1 # x will be +1 or -1 depending on the values of a and b
Python Built-ins
The following Python built-ins are supported in SNAPpy:
chr Given an integer, returns a one-character string whose ASCII is that number. The result of
chr(65)
is 'A '.
int Given a string, returns an integer representaon of the string. The result of
int('5 ') is 5.
len Returns the number of items in an object. This will be an element count for a tuple, or the number
of characters in a string.
ord Given a one-character string, returns an integer of the ASCII for that character. The result of
ord('A') is 65.
type Given a single argument, it returns an integer indicang the data type of the argument. Note that
the format of the return value is different from that returned in Python. The
type() funcon is new in
SNAP 2.5.
str Given an element, returns a string representaon of the element. The result of
str(5) is '5' for
example. The result of
str(True) is 'True '.
Addionally, many RF module-specific embedded network and control built-ins are supported.
Print
SNAPpy also supports a print statement. Normally each line of printed output appears on a separate line. If you
do not want to automacally advance to the next line (if you do not want an automac Carriage Return and Line
Feed), end your print statement with a comma (“,”) character.
print "line 1"
print "line 2"
print "line 3 ",
print "and more of line 3"
print "value of x is ", x, " and y is ", y
SNAP® Network Operang System 15