Skip to content

← programming package

NumElements

Get the number of elements in the given object.

By default, this counts the elements at the top level of the object, which amounts to the number of chunks in a packet, the number of entries in a list, the number of key-value pairs in a dictionary, the number of characters in a string, the total number of elements in an array, block, or chunk, the length of an axis, the number of nodes in a graph, and 1 for all other objects (except None, which is 0 unless count_none is set). If recursive is set, it will instead inspect the content of the individual elements and descend into lists, sets, dictionaries and the chunks of packets, and sum up the number of elements in each contained sub-object, and ultimately only tally the corresponding indivisable "leaf" elements. This is most useful to detect packets containing only empty chunks, the total count of numbers contained in a list of lists, the total number of list elements excluding None's, and so forth. Note that for a list of strings, this will count the total number of characters in the contained strings, and nothing more or less; thus, if those strings are present but all empty, the recursive count can be lower (i.e. 0) than the non-recursive count (i.e. the number of strings). The same applies to lists of empty lists, packets with only empty chunks, and so forth. Since None is treated by default as 0, this can also be used as a generic pass/fail check for empty objects. For programmers: note that this will not return the len() or .size of any other object types that may have this defined that are not listed above. None is treated as an empty object, unless pass_through_none is set, in which case None is emitted. Version 1.1.0

Ports/Properties

data

Input object.

  • verbose name: Data
  • default value: None
  • port type: DataPort
  • value type: object (can be None)
  • data direction: IN

result

Result.

  • verbose name: Result
  • default value: None
  • port type: DataPort
  • value type: int (can be None)
  • data direction: OUT

recursive

If set, then the number of elements will be calculated recursively, that is the number of elements in each contained object will be calculated and summed up. For Packets, by default (if disabled) this will count only the chunks (regardless of contents), but if enabled, it will instead return the sum of numeric entries across chunks; note that this can be zero if chunks are present but contain no data. The node also descends into lists, dictionaries, and sets. None can optionally be counted as 0 or 1 depending on the count_none port. See the overall node documentation for additional details.

  • verbose name: Recursive
  • default value: False
  • port type: BoolPort
  • value type: bool (can be None)

count_none

If set, then None values will be counted as 1, otherwise 0.

  • verbose name: Count None
  • default value: False
  • port type: BoolPort
  • value type: bool (can be None)

pass_through_none

If set, then None values will silently pass through as None, otherwise it will be treated as an empty object.

  • verbose name: Pass Through None
  • default value: False
  • port type: BoolPort
  • value type: bool (can be None)

set_breakpoint

Set a breakpoint on this node. If this is enabled, your debugger (if one is attached) will trigger a breakpoint.

  • verbose name: Set Breakpoint (Debug Only)
  • default value: False
  • port type: BoolPort
  • value type: bool (can be None)

metadata

User-definable meta-data associated with the node. Usually reserved for technical purposes.

  • verbose name: Metadata
  • default value: {}
  • port type: DictPort
  • value type: dict (can be None)