Specifications

Scripts that do string manipulations that were written to work within the 2.0/2.1 restrictions will still
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, shifting, arithmetic, 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.
int – Given a string, returns an integer representation of the string. The 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.
str – Given an element, returns a string representation of the element. The str(5) is ‘5’ for example.
Additionally, 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 automatically advance to the next line (if you do not want an automatic
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
Printing multiple elements on a single line in SNAPpy produces a slightly different output from how
the output appears when printed from Python. Python inserts a space between elements, where
SNAPpy does not.
SNAPpy also imposes some restrictions on the printing of nested tuples. You may nest tuples,
however printing of nested tuples will be limited to three layers deep. The following tuple:
(1,'A',(2,'b',(3,'Gamma',(4,'Ansuz'))))
will print as:
('A',1,(2,'b',(3,'Gamma',(...
SNAPpy also handles string representations of tuples in a slightly different way from Python. Python
inserts a space after the comma between items in a tuple, while SNAPpy does not pad with spaces, in
order to make better use of its limited string-processing space.
Page 24 of 202 SNAP Reference Manual Document Number 600-0007K