Fieldcode Manual

Tip: You can use filters for better results


Global functions and data types

Copy the URL link to this section to share

This topic describes the globally available functions and classes in Fieldcode Embedded Python.


Global functions

Copy the URL link to this section to share

abs(x)

Return the absolute value of x. x must be a number.

all(iterable)

Returns True if all elements of the iterable are True, returns False otherwise. iterable must be either a list or set.

any(iterable)

Returns True if any element of the iterable is True, returns False otherwise. iterable must be either a list or set.

cast(object, classinfo)

Casts the given object to the given classinfo if possible.

ceil(number)

Returns the nearest integer greater than number. number must be a number.

cmp(x,y)

Returns 1, 0 or -1 if x is greater than, equal to or less than y, respectively. x and y must be the same type and must be comparable.

filter(function,iterable)

Applies the function to each element of the iterable and returns the matching results. function must be a predicate lambda with one argument of the same type as the elements of iterable and iterable must be either a list or set.

flatmap(function,iterable)

Applies the function to each element of the iterable and joins all results into a single iterable. function must be a lambda with one argument of the same type as the elements of iterable which returns either a list or set and iterable must be either a list or a set.
It is especially useful when the user needs to extract multiple values from each element of a single iterable. Alternatively, it is equivalent to reduce(lambda a, b: a.extend(b), map(function, iterable)), however due to the current limitations of the system, multi-dimensional iterables are not supported and thus only flatmap will work in this scenario.

floor(number)

Returns the nearest integer less than number. number must be a number.

len(s)

Returns the length of s. s must be either a string, list or set.

map(function,iterable)

Applies the function to each element of the iterable and returns the mapped results. function must be a lambda with one argument of the same type as the elements of iterable and iterable must be either a list or set.

max(iterable)

Returns the greatest value element of the iterable. iterable must be either a string, list or set.

max(arg1,arg2,args…)

Returns the greatest value argument. All arguments must be the same type and must be comparable.

min(iterable)

Returns the lowest value element of the iterable. iterable must be either a string, list or set.

min(arg1,arg2,args…)

Returns the lowest value argument. All arguments must be the same type and must be comparable.

pow(x, y[, z])

Returns x to the power of y modulo z if z is provided, returns x to the power of y otherwise. All arguments must be numbers.

range(stop)

Returns a list of numbers from 0 to stop. stop must be a number.

range(start, stop[, step=1])

Returns a list of numbers from start to stop, incrementing by step. All arguments must be a numbers.

reduce(function, iterable[, identity])

Applies the function to combine each element of the iterable with the previous result. Combines the first element with identity if provided, otherwise the iteration starts with combining the first two elements. function must be a lambda with 2 arguments of the same type as the elements of iterable, iterable must be either a list or set and identity must be the same type as the iterable values if provided.

repr(object)

Returns the string representation of object.

round(number[, ndigits=0])

Returns number rounded to ndigits decimal places. All arguments must be numbers.

sleep(ms)

Causes execution to be suspended for the number of milliseconds specified in ms. ms must be a number.

sum(iterable[, start=0])

Returns the total of the elements of the iterable, starting with start if provided. iterable must be either a list or set of numbers and start must be a number if provided.


Data types

Copy the URL link to this section to share

Date and time types are supported through the fcdatetime module


Booleans

Copy the URL link to this section to share

A bool is a Boolean value, i.e. one of True or False.
Its only instances are False and True.

Constructor:

class bool([x=False])

Returns the logical value of x, i.e. False if x is None or False, True otherwise. Returns False if x is omitted.

Boolean operations – and, or, not
There are the Boolean operations, ordered by ascending priority:

Edit
Operation Result
x or y if x is false, then y, else x
x and y if x is false, then x, else y
not x if x is false, then True, else False


Comparable Types

Copy the URL link to this section to share

Fieldcode Embedded Python has only two comparable types: string and number objects.

 


Comparisons

Copy the URL link to this section to share

Comparison operations are supported by all comparable objects. They all have the same priority (which is higher than that of the Boolean operations). Comparisons can be chained arbitrarily; for example, x < y <= z is equivalent to x < y and y <= z, except that y is evaluated only once (but in both cases z is not evaluated at all when x < y is found to be false).

This table summarizes the the comparison operations:

Edit
Operation Result
x < y is x strictly less than y
x <= y is x less than or equal to y
x > y is x strictly greater than y
x >= y is x greater than or equal to y
x == y is x equal to y
x != y is x not equal to y
x is y is x sam as y (1)
x is not y is x not the same as y (1)

Notes:

  1. In Fieldcode Embedded Python is and is not operations behave the same as == and != operations.


Numbers

Copy the URL link to this section to share

A number is a collective type for the standard int, float and long types.

Constructor:

class number([x=0])

Parses the x into a number when provided with a string, returns the provided number otherwise. Returns 0 if x is omitted.

Arithmetic Operations

The number type supports the following operations:

Edit
Operation Result
x + y sum of x and y
x – y difference of x and y
x * y product of x and y
x / y quotient of x and y
x // y (floored) quotient of x and y
x % y remainder of x / y
x ** y x to the power of y
-x x negated
+x x unchanged

Bitwise Operations

Bitwise operations (|, ^, &, >>, <<, ~) are not supported.


Sequence Types

Copy the URL link to this section to share

Bitwise operations (|, ^, &, >>, <<, ~) are not supported.

Sequence Operations

This table lists the sequence operations sorted in ascending priority. In the table, s and t are sequences of the same type; n, i and j are integers:

Edit
Operation Result
x in s True if an item of s is equals to x, else False
x not in s False if an item of s is equals to x, else True
s + t concatenation of s and t
s * n, n * s concatenation of s with itself n times
s[i] ith item of s, origin 0
s[i:j] slice of s from i to j
s[i:j:k] slice of s from i to j with step k
s.index(x) index of the first occurrence of x in s
s.count(x) total number of occurrences of x in s


String Literals

Copy the URL link to this section to share

String literals are written in single or double quotes: ‘xyzzy’, “frobozz”.

Constructor:

class str([x=”])

Returns the string representation of x. Returns an empty string if x is omitted.

String Methods

Below the supported string methods are listed:

In addition, Python’s strings support the sequence-type methods and operations described in the Sequence Types section.

str.count(value[, start[, end]])

Returns the number of non-overlapping occurrences of substring value within the slice s[start:end]. value must be a string and start and end must be numbers if provided.

str.endswith(value[, start[, end]])

Returns True if the string within the slice s[start:end] ends with the specified value, otherwise returns False. value must be a string and start and end must be numbers if provided.

str.find(value[, start[, end]])

Returns the lowest index in the string where substring value is found within the slice s[start:end]. Returns -1 if value is not found. value must be a string and start and end must be numbers if provided.

str.format(*args)

Performs a string formatting operation. Fieldcode Embedded Python uses Java Format String Syntax as the transpiled code is evaluated in a JVM.

str.index(value[, start[, end]])

Returns the lowest index in the string where substring value is found within the slice s[start:end]. Returns -1 if value is not found. value must be a string and start and end must be numbers if provided.

str.isalnum()

Returns True if all characters in the string are alphanumeric and there is at least one character, False otherwise.

str.isalpha()

Returns True if all characters in the string are alphabetic and there is at least one character, False otherwise.

str.isdigit()

Returns True if all characters in the string are digits and there is at least one character, False otherwise.

str.join(iterable)

Returns a string which is the concatenation of the elements in iterable. iterable must be either a list or set of strings.

str.lower()

Returns a copy of the string with all cased characters converted to lowercase.

str.matches(regex)

Returns True if the string matches the provided regex pattern, False otherwise. regex must be a string with a valid regular-expression.

str.replace(search, replacement[, count])

Returns a copy of the string with all occurrences of substring search replaced by replacement. If the optional count is given, only the first count occurrences are replaced. search and replacement must be strings and count must be a number if provided.

str.split([sep[, max]])

Return a list of the words in the string, using sep as the delimiter string. If max is given, at most max splits are done (thus, the list will have at most max+1 elements). sep must be a string if provided and max must be a number if provided.

str.splitlines()

Returns a list of the lines in the string, breaking at line boundaries. Line breaks are not included in the resulting list.

str.startswith(value[, start[, end]])

Returns True if the string within the slice s[start:end] starts with the specified value, otherwise returns False. value must be a string and start and end must be numbers if provided.

str.strip()

Returns a copy of the string with the leading and trailing whitespace characters removed.

str.upper()

Returns a copy of the string with all cased characters converted to uppercase.


Sets

Copy the URL link to this section to share

A set object is an unordered collection of distinct objects. Common uses include membership testing, removing duplicates from a sequence, and computing mathematical operations such as intersection, union, difference, and symmetric difference.

Fieldcode Embedded Python only supports an immutable set type which is more or less equivalent to the original frozenset type.

Constructor:

class set([iterable])

Returns a new immutable set object whose elements are taken from iterable. Sets of collections are currently not supported. If iterable is not specified, a new empty set is returned.

 

str.upper()

Returns a copy of the string with all cased characters converted to uppercase.

Set Operations

The supported set methods and operations are listed below.

In addition, Python’s sets support the x in s and x not in s operations described in the Sequence Types section.

set.isdisjoint(other)

Returns True if the set has no elements in common with other. In other words, sets are disjoint if and only if their intersection is the empty set. other must be a collection of the same type.

set.issubset(other), set <= other

Returns True if every element in the set is also in other. other must be a collection of the same type.

set < other

Returns True if set is a proper subset of other, that is, set <= other and set != other. other must be a collection of the same type.

set.issuperset(other), set >= other

Returns True if every element in other is also in the set. other must be a collection of the same type.

set < other

Returns True if set is a proper subset of other, that is, set <= other and set != other. other must be a collection of the same type.

set.issuperset(other), set >= other

Returns True if every element in other is also in the set. other must be a collection of the same type.

set < other

Returns True if set is a proper superset of other, that is, set >= other and set != other. other must be a collection of the same type.

set.union(other), set | other

Returns a new set with elements of the set and other. other must be a collection of the same type.

set.intersection(other), set & other

Returns a new set with elements common to the set and other. other must be a collection of the same type.

set.difference(other), set – other

Returns a new set with elements in the set that are not in other. other must be a collection of the same type.

set.symmetric_difference(other), set ^ other

Returns a new set with elements in either the set or other but not both. other must be a collection of the same type.


Lists

Copy the URL link to this section to share

A list object is an ordered collection of objects.

Fieldcode Embedded Python only supports an immutable list type.

Constructor:

class list ([iterable])

Returns a new immutable list object whose elements are taken from iterable. Lists of collections are currently not supported. If iterable is not specified, a new empty list is returned.

List Methods

Below are listed the supported list methods.

In addition, Python’s lists support the sequence-type methods and operations described in the Sequence Types section.

list.append(value)

Returns a new list with the elements of list appended by value. value will be placed at the end of the new list. value must be the same type as the elements of the list.

list.distinct()

Returns a new list without duplicate elements of list. This is a faster equivalent to list(set(list)) to filter out duplicates of the list.

list.extend(other)

Returns a new list with the elements of list and other. other must be a collection of the same type.

list.index(value[, start=0[, end=len(list) – 1]])

Returns the smallest k where list[k] == value and start <= k <= end. Returns -1 if such k is not found. value must be the same type as the elements of the list and start and end must be numbers if provided.

list.insert(index, value)

Returns a new list with the elements of list and value. value will be placed at index of the new list. value must be the same type as the elements of the list and index must be a number.

list.remove(value)

Returns a new list with the elements of list without value. If value appears more than one time in the list, only the first occurrence will be removed. value must be the same type as the elements of the list.

list.replace(index, value)

Returns a new list with the elements of list where the indexth element is replaced by value. value must be the same type as the elements of the list and index must be a number.

list.reverse()

Returns a new list with the elements of list in reverse order.

list.sort([cmp])

Returns a new list with the elements of list sorted using cmp. If cmp is not provided, default sorting methods will be used. cmp must be a lambda with 2 arguments of the same type as the elements of the list which returns a number.
Also see cmp(x, y) -> Global functions, fifth one.


Dicts

Copy the URL link to this section to share

A dictionary object is a mapping object that maps values to arbitrary objects.

Fieldcode Embedded Python only supports an immutable version of the dict type with string type keys only.

Constructor:

class dict()

Returns a new empty immutable dictionary object.

Dict Methods

Below are listed the supported dictionary methods:

dict[key]

Returns the value object mapped by key. Returns None if key is unmapped. key must be a string.

dict.merge(other)

Returns a new dict which includes mappings from both dictionary objects. If a mapping occurs in both dictionaries then the mapping from other will be taken. other must be a dict.

dict.remove(key)

Returns a copy of the dict where key is unmapped. key must be a string.

dict.replace(key, value)

Returns a copy of the dict where key is mapped to value. key must be a string.

Was this topic helpful?
0 out of 5 stars
5 Stars 0%
4 Stars 0%
3 Stars 0%
2 Stars 0%
1 Stars 0%
5
How can we further improve this topic?
Please provide the reason for your vote. This will help us improve this topic.
Navigation