astor -- AST observe/rewritesteemCreated with Sketch.

in #utopian-io7 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

Sort:  

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!

Coin Marketplace

STEEM 0.20
TRX 0.25
JST 0.039
BTC 97549.65
ETH 3484.99
USDT 1.00
SBD 3.21