Skip to content

Instantly share code, notes, and snippets.

@mvantellingen
Last active December 18, 2018 12:52
Show Gist options
  • Save mvantellingen/e6843838a19975520db4815cb3b0e311 to your computer and use it in GitHub Desktop.
Save mvantellingen/e6843838a19975520db4815cb3b0e311 to your computer and use it in GitHub Desktop.
Code Generation blog post
>>> import ast, astunparse
>>> node = ast.parse("value = {'foo': 'bar'}")
>>> print(ast.dump(node))
Module(body=[Assign(
targets=[Name(id='value', ctx=Store())],
value=Dict(keys=[Str(s='foo')], values=[Str(s='bar')])
)])
>>> code = astunparse.unparse(node)
>>> print(code)
value = { 'foo': 'bar', }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment