Using Python functions as UDF() functions

Using the built-in UDF() (user-defined-) function you can call any Python modules/functions in formulas in GS-Base.
This can help you to significantly increase GS-Base functionality thanks to the large number of various Python modules and libraries including, for example, science, finance, graphics.

From GS-Base you can pass to Python functions any type of parameters: (double precision) numbers, text strings, ranges of field values as numeric arrays/matrices, automatically saved blocks of CSV data from field ranges.

GS-Base can accept from Python functions any type of data it supports in formulas: (double precision) numbers, text strings, numeric arrays/matrices, CSV data blocks and images/graphics/charts to be inserted in the LongText, Images/Files, Code binary fields.

The UDF() function:

UDF(module, function, type, parameter1, parameter2, ...)

Python modules are plain text files with the "*.py" extension. Below is an example of such a file containing seven simple functions.

e:\example.py :


def function1():
   return 10

def function2(a, b):
  return a + b

def function3(text):
   return 'A new text with ' + text + ' inserted in the middle'

def function4(csvdata):
   return csvdata

def function5(csvFilePath):
   f = open(csvFilePath, 'rb')
   file_content = f.read()
   f.close()
   return file_content

def function6(imageFilePath):
   f = open(imageFilePath, 'rb')
   file_content = f.read()
   f.close()
   return bytearray(file_content)

In GS-Base the above functions can be use as follows:

Related Topics

Installing Python and integrating it with GS-Base