Call a Python function and return the result. This is the main way to call custom Python functions from FileMaker. You need this function if you're going to write your own functions in Python to call from FileMaker.
PyRun is meant to be used in production; during development you may find it more convenient to use PyLab, which automatically reloads changed files.
To learn how to write your own functions you can call with PyRun read .
PyRun( ); ;
module
string, case-sensitivePython module name; can also be a submodule name, e.g. os.path
.
object
string, case-sensitiveName of a callable object (usually a function) or any object that can be
directly returned to FileMaker in the module
.
arugments
Optional arguments as required by the callable. If the object is not callable, the function will ignore the arguments.
The final result and side effects depend on the called function. PyRun itself may return the following:
If the module
parameter is not text: The module parameter for PyRun
must be text, not <TYPE-NAME>
(class: TypeError
).
If the object
parameter is not text: The object parameter
for PyRun must be text, not <TYPE-NAME>
(class: TypeError
).
If the number of parameters is too large for Python: Cannot call the PyRun
function because the number of parameters (<NUMBER>) exceeds the Python
limit (<NUMBER>)
(class: TooManyParameters
). This is probably never
going to happen because the limits are very high.
If the function returned an empty list or tuple: Cannot convert an empty
<TYPE-NAME> to FileMaker
(class: TypeError
).
PyRun( "os"; "getcwd" )
This call will run the getcwd
method of the os
module and return the
current working directory.
The results depend on the platform and from the last operation FileMaker did with files. For example, if you insert a file into a container, then that directory becomes the current directory in FileMaker.
PyRun( "os.path"; "sep" )
This call will return the value of os.path.sep
, which is the path
separator on the current platform. On Mac OS X the result will be /
, on
Windows \
.
PyRun( "datetime"; "datetime.utcnow" )
This will return the current timestamp in the UTC (GMT) timezone. The precision of the result depends on the platform, I guess, but it should be up to at least milliseconds (FileMaker itself supports time precision up to a microsecond).
PyRun( "math"; "log"; 100 )
This will return the logarithm of 100 to the base e (the so-called natural logarithm) and will be a number approximately equal to 4.6. The e is the default base, but you can specify another:
PyRun( "math"; "log"; 100; 10 )
This one will return the logarithm of 100 to the base 10, which is 2.