Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Custom Action Code Parameter? [Solved]
-
How do I pass the contents of a code parameter in a custom action, to the next action as code?
workflow.get_input() doesnt work.
If it is not possible, what is the use?
Here is what I have so far.
-
Does the ast module do what I require?
ast.literal_eval(node_or_string)
Safely evaluate an expression node or a string containing a Python expression. The string or node provided may only consist of the following Python literal structures: strings, numbers, tuples, lists, dicts, booleans, and None.This can be used for safely evaluating strings containing Python expressions from untrusted sources without the need to parse the values oneself.
If so, how?
The exec statement?
exec_stmt ::= "exec" or_expr ["in" expression ["," expression]]
This statement supports dynamic execution of Python code. The first expression should evaluate to either a string, an open file object, a code object, or a tuple. If it is a string, the string is parsed as a suite of Python statements which is then executed (unless a syntax error occurs). [1] If it is an open file, the file is parsed until EOF and executed. If it is a code object, it is simply executed. For the interpretation of a tuple, see below. In all cases, the code that’s executed is expected to be valid as file input (see section File input). Be aware that the return and yield statements may not be used outside of function definitions even within the context of code passed to the exec statement.
-
I solved it! I just use an exec statement:
import workflow
source = workflow.get_input()
exec source