User manual
Subscripng
Subscripng 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 operaon
(slicing, concatenaon, subscripng, etc.). Subsequent operaons 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 operaon. 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 manipulaons that were wrien to work within the 2.0/2.1 restricons will sll 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, shiing, arithmec, 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 representaon 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 indicang the data type of the argument. Note that
the format of the return value is different from that returned in Python. The
type() funcon is new in
SNAP 2.5.
• str – Given an element, returns a string representaon of the element. The result of
str(5) is '5' for
example. The result of
str(True) is 'True '.
Addionally, 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 automacally advance to the next line (if you do not want an automac 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 Operang System 15