Testing Your Expressions

Install python IDLE from Ninite:

https://ninite.com/

       
        functions={"slice": slice,
                    "len":
        len,
                   
        "replace":str.replace,
                    "split":
        str.split,
                    "splitlines":
        str.splitlines,
                    "get_literal":
        ast.literal_eval,
                    "dict_get":
        dict.get,
                    "str":
        str,
                    "int":
        int,
                    "float":
        float,
                    "unicode":
        unicode,
                    "date":
        datetime.date,
                    "time":
        datetime.time,
                    "datetime":
        datetime,
                    "strftime":
        datetime.strftime,
                    "datetimenow":
        datetime.now,
                    "strptime":
        datetime.strptime,
                    "tznow":
        tznow,
                    "get_obj":
        self.get_obj,
                    "str_upper":
        str.upper,
                    "str_lower":
        str.lower,
                    "get_qs":
        self.get_qs,
                    "chr" :
        chr,
                    "gs" :
        gs,
                    "gs1_li_code" :
        gs1_li_code,
                    "gs1_dm_code" :
        gs1_dm_code}
Note: the above functions do not get looked up with the \~ because they are built-in.

\~ is used for field look ups like column name or field functions. Additionally, standard functions get embedded so they do not need to be looked up.

If you are not able to install simple eval, you need to test on your local windows, mac, or linux computer with eval instead.

Note: you will need to look at the functions mapping to see how to map python commands to simple eval. For instance, "dict_get": dict.get, from above.

obj = {'container.container_nbr': 'x',

'order_header.destination_company.code': 'AE',

'order_header.dest_facility.code': '*',

'company.code': 'ACME'}

expression = 'str(dict.get(obj, "company.code"))[slice(5, len(dict.get(obj,
        "company.code")))]'

print eval(expression)

You will need to swap back your expression afterwards so that it says the following:

str(dict_get(get_obj(), "company.code"))[slice(5,len(dict_get(get_obj(),
        "company.code")))]

This allows it to work within the expression field in document label designer.

Another example:

obj = {'container.container_nbr': 'x',

'order_header.destination_company.code': 'AE',

'order_header.dest_facility.code': '*',

'company.code': 'ACME'}

expression = '"" if str(dict.get(obj,
        "order_header.destination_company.code")) == "*" else str(dict.get(obj,
        "order_header.destination_company.code"))'

print eval(expression)

The expression that goes into document label designer is:

"" if
        str(dict_get(get_obj(), "order_header.destination_company.code")) == "*" else
        str(dict_get(get_obj(), "order_header.destination_company.code"))

Another example of developing an expression in IDLE:

expression = 'str("(No 000111)") if len(cust.split(";")) < 12 else str("(No " +
        cust.split(";")[11] + "000111" + ")")'
print eval(expression)

The expression that goes into document label designer is:

str("(No \~order_header.customer_number)") if
        len(split("\~order_header.custom_field_5", ";")) < 12 else str("(No " +
        split("\~order_header.custom_field_5", ";")[11] + "\~order_header.customer_number" +
        ")")