Message Boards Message Boards

GROUPS:

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

Posted 18 days ago
251 Views
|
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?

B

Here is a description of the objects: https://greentreesnakes.readthedocs.io/en/latest/tofrom.html

Posted 7 days ago
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract