Message Boards Message Boards


How to assemble Python abstract syntax trees (AST) in Mathematica?

Posted 8 months ago
1 Reply
0 Total Likes

I would like to assemble Python 'ast.Module' objects inside of Wolfram Language and then submit them to Python via e.g. ExternalEvaluate["exec(astObject)"].

The Python ast, parse, eval, exec and compile functions can all operate on 'ast.Module' objects, either outputting them or taking them as inputs. However I don't know how I might assemble this object and send it over ExternalEvaluate.

I am trying to programmatically generate Python code on the Wolfram Language side (for a genetic algorithm) and then submit it to Python for evaluation. I could assemble Python code strings, but then I have to handle all of the indentation, which seems like a pain.

How can one create arbitrary Python objects on the Wolfram Language side?


Here is a description of the objects:

Posted 8 months ago
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract