astor -- AST observe/rewrite
I'm the primary maintainer of astor, a library that lets you manipulate Python code in the AST level. It has a lot of features, but the most important one is that it generates valid Python code via an AST tree (which the ast module in the Python standard library doesn't provide a way to do this)
You can install astor via pip:
$ pip install astor
For example, Hy is a Lisp dialect that's embedded in Python (I'm also a Hy core developer) It converts Lisp syntax to an AST tree and then to Python bytecode. We use astor to show users the Python equivalent of the Lisp code in the Hy REPL:
$ hy --spy
hy 0.13.0 using CPython(3.4:c7b9645a6f35) 3.4.3+ on Linux
=> (defn hello [name] name)
from hy.core.language import name
def hello(name):
return name
=> (defn hello [name] (print (% "Hello %s!" name)))
from hy.core.language import name
def hello(name):
return print(('Hello %s!' % name))
=> (hello "utopians")
hello('utopians')
Hello utopians!
And here is an example without using Hy:
import ast
import astor
print(astor.to_source(ast.parse('def foo(i): return 2 * i')))
This will output:
def foo(i):
return 2 * i
Since I've become the maintainer of astor in 2013, I've created documentation, test suite, and reviewed pull requests created by multiple contributors.
Open Source Contribution posted via Utopian.io
Congratulations @berkerpeksag! You have completed the following achievement on Steemit and have been rewarded with new badge(s) :
Award for the number of upvotes
Click on the badge to view your Board of Honor.
If you no longer want to receive notifications, reply to this comment with the word
STOP
Thanks @berkerpeksag33. Accepted in Utopian
[utopian-moderator]
Hey @berkerpeksag I am @utopian-io. I have just super-voted you at 26% Power!
Suggestions https://utopian.io/rules
Achievements
Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x
Congratulations @berkerpeksag! You have completed some achievement on Steemit and have been rewarded with new badge(s) :
You made your First Vote
Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here
If you no longer want to receive notifications, reply to this comment with the word
STOP
Congratulations @berkerpeksag! You have completed some achievement on Steemit and have been rewarded with new badge(s) :
Award for the number of upvotes
Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here
If you no longer want to receive notifications, reply to this comment with the word
STOP
Congratulations @berkerpeksag! You have completed some achievement on Steemit and have been rewarded with new badge(s) :
Award for the number of upvotes
Click on any badge to view your Board of Honor.
For more information about SteemitBoard, click here
If you no longer want to receive notifications, reply to this comment with the word
STOP
Do not miss the last announcement from @steemitboard!
@berkerpeksag you were flagged by a worthless gang of trolls, so, I gave you an upvote to counteract it! Enjoy!!
Congratulations @berkerpeksag! You have completed some achievement on Steemit and have been rewarded with new badge(s) :
You got a First Vote
Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here
If you no longer want to receive notifications, reply to this comment with the word
STOP
Congratulations @berkerpeksag! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :
Award for the number of upvotes
Click on the badge to view your Board of Honor.
If you no longer want to receive notifications, reply to this comment with the word
STOP
Congratulations @berkerpeksag! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :
Click here to view your Board of Honor
If you no longer want to receive notifications, reply to this comment with the word
STOP
Do not miss the last post from @steemitboard: