User manual

4. SNAPpy versus Python
Here are more details about SNAPpy, with emphasis on the differences between SNAPpy and Python.
Modules
SNAPpy supports import of user-defined as well as standard predefined Python source library modules.
from module import * # Supported
from module import myFunction # Supported
import module # Not supported
Variables
Local and Global variables are supported. On RAM-constrained devices, SNAPpy images are typically limited to
64 system globals and 64 concurrent locals. Per-plaorm values are given in the SNAP Reference Manual.
Funcons
Up to 255 “public” funcons may be defined. These are remotely callable using the SNAP RPC protocol, and
include the SNAPpy built-in funcons.
Non-public funcons (prefixed with underscore) are limited only by the size of FLASH memory. These are not
remotely callable, but can be called by other funcons in the same script. (That is what it means to be non-
public.)
Any non-public funcons contained in an imported module will not be included when using
from module
import *
, but you can explicitly import non-public funcons using from module import _myFunction.
It is not recommended that you use non-public funcons for hooked events, as scripts with a large number of
constants and/or funcons (public and non-public) can cause the hooks to invoke the wrong script at run-me.
Data Types
SNAPpy supports the following fundamental Python data types:
NoneType None is a valid value
int An int in SNAPpy is a signed 16-bit integer, -32768 through 32767. 32767 + 1 = -32768.
bool A bool has a value of either True or False. (Note that those are case-sensive.)
string A stac string has a maximum size of 255 bytes. If you assign a literal to a string when the string
is created, either inside a funcon or as a global, this is the size limit that will be applied. However if you
assign a value to a string while a script is running, or aempt to reassign a value to a string declared
outside a funcon, SNAPpy uses a different collecon of string buffers, and the maximum length of the
string will be determined by the plaorm on which SNAP is running. See the plaorm-specific
parameters in the SNAP Reference Manual for more details. (Note built-in funcons slice/concat/rpc
enforce smaller limits on what they can do with strings.)
tuple A tuple is a read-only container of data elements, e.g., (1,'A',True). SNAPpy tuples must be global
in scope and cannot be used outside the scope of a local script. You cannot pass them as parameters in
RPC calls to other nodes. Each element in a tuple can be any supported data type, including another
tuple. However there are restricons on the prinng of nested tuples. (See the details about prinng
later in this document.)
funcon A funcon is a user-defined subroune invoked from elsewhere in your script, or by RPC call
from another node.
SNAP® Network Operang System 13