PYLOGICAL( ) function

Returns a logical value calculated by a function in an external Python script. Data processing in Python is external to Analytics.

Syntax

PYLOGICAL("PyFile,PyFunction" <, field|value <,...n>>)

Parameters

Name Type Description
PyFile,PyFunction

character

The name of the Python script to run followed by a comma and then the name of the function that returns the value:

 "myScript,myFunction"

When specifying the Python script, omit the file extension. The function you call may call other functions within the script or within other scripts, however all scripts that run must be placed inside a folder in the PYTHONPATH system environment variable prior to running.

For more information, see Configuring Python for use with Analytics.

Note

Your PyFunction must return a Python truth value.

field |value <,...n>

optional

character

numeric

datetime

logical

This list of fields, expressions, or literal values to use as arguments for the Python function. The values are passed into the function you call in the order you specify them.

You may include as many arguments as necessary to satisfy the function definition in the Python script.

Note

Use the ALLTRIM() function to remove any leading or trailing spaces from character input: ALLTRIM(str). For more information, see ALLTRIM( ) function.

Output

Logical.

Examples

Basic examples

Returns F:

PYLOGICAL( "hello,str_compare", "basketball", "baseball", "b" )

External Python script that compares str1 and str2 using the count of the character that is passed in as char:

# hello.py content
def str_compare(str1, str2, char):
    return str1.count(char) > str2.count(char)

Advanced examples

Using fields

Returns a truth value when comparing Vendor_Name and Vendor_City:

PYLOGICAL( "hello,str_compare", Vendor_Name, Vendor_City, "b" )

External Python script that compares str1 and str2 using the count of the character that is passed in as char:

# hello.py content
def str_compare(str1, str2, char):
    return str1.count(char) > str2.count(char)
ACL Scripting Guide 14.1