Message Boards Message Boards

1
|
4391 Views
|
1 Reply
|
1 Total Likes
View groups...
Share
Share this post:

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

Posted 3 years ago

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 BY: Bernard Gress
Posted 3 years 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