astor -- AST observe/rewritesteemCreated with Sketch.

in utopian-io •  7 years ago 

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

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

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

Do you like SteemitBoard's project? Then Vote for its witness and get one more award!

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

  • Your contribution is less informative than others in this category.

Achievements

  • I am a bot...I love developers... <3
  • You have less than 500 followers. Just gave you a gift ;)
  • You just got more votes than your total number of followers. Rock Star!
  • This is your first accepted contribution here in Utopian. Welcome!
    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

Upvote this notification to help all Steemit users. Learn why here!

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

Upvote this notification to help all Steemit users. Learn why here!

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!

Do you like SteemitBoard's project? Vote for its witness and get one more award!

@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

By upvoting this notification, you can help all Steemit users. Learn how here!

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

Support SteemitBoard's project! Vote for its witness and get one more award!

Congratulations @berkerpeksag! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

You made more than 800 upvotes. Your next target is to reach 900 upvotes.

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:

SteemFest3 and SteemitBoard - Meet the Steemians Contest

Support SteemitBoard's project! Vote for its witness and get one more award!

Congratulations @berkerpeksag! You have received a personal award!

1 Year on Steemit
Click on the badge to view your Board of Honor.

Do not miss the last post from @steemitboard:

SteemFest3 and SteemitBoard - Meet the Steemians Contest

Support SteemitBoard's project! Vote for its witness and get one more award!

Congratulations @berkerpeksag! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

You made more than 900 upvotes. Your next target is to reach 1000 upvotes.

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:

Saint Nicholas challenge for good boys and girls

Support SteemitBoard's project! Vote for its witness and get one more award!

Congratulations @berkerpeksag! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

You made more than 1000 upvotes. Your next target is to reach 1250 upvotes.

Click here to view your Board
If you no longer want to receive notifications, reply to this comment with the word STOP

Do not miss the last post from @steemitboard:

Christmas Challenge - The party continues

Support SteemitBoard's project! Vote for its witness and get one more award!

Congratulations @berkerpeksag! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 2 years!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Do not miss the last post from @steemitboard:

SteemFest Meet The Stemians Contest - The mysterious rule revealed
Vote for @Steemitboard as a witness to get one more award and increased upvotes!