Last active
December 18, 2018 12:52
-
-
Save mvantellingen/e6843838a19975520db4815cb3b0e311 to your computer and use it in GitHub Desktop.
Code Generation blog post
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> 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