In [1]:
import showast
In [2]:
%%showast
print 1 + 2
In [3]:
%%showast
a = 1
b = a + 2
b /= 2.
In [4]:
%%showast
x.y.z().t
In [5]:
%%showast
def abc():
for x in 'abc':
print x
return 0
In [6]:
%%showast
a, b = [x for x in y if x.z]
In [7]:
%%showast
@decorator()
def decorated():
import time
yield time.time()
In [8]:
# showast can also be used to visualize inspectable objects
from showast import show_source
import antigravity
show_source(antigravity)
In [9]:
import random
show_source(random.choice)
In [10]:
import contextlib
show_source(contextlib.closing.__enter__)
show_source(contextlib.closing.__exit__)
In [11]:
# styling options can also be set
from showast import Settings
Settings['font'] = 'Century'
Settings['shape'] = 'oval'
Settings['nonterminal_color'] = '#7733AA'
In [12]:
%%showast
def add(x, y):
return x + y
In [13]:
# nltk and pillow can be used as an alternate rendering engine
from showast import Renderers
Settings['renderer'] = Renderers.nltk
# reset styling:
Settings['font'] = 'courier'
Settings['shape'] = 'none'
Settings['nonterminal_color'] = '#004080'
In [14]:
%%showast
while b != 0:
if a > b:
a = a - b
else:
b = b - a
print a