forked from lowks/pythonpy
-
Notifications
You must be signed in to change notification settings - Fork 0
More Examples
Russell Stewart edited this page Mar 20, 2015
·
53 revisions
Run a statement as you would using python -c with py -c:
py -c 'a = 5; print(`a`)' a
Alternatively:
py -c 'a = 5' 'a' 5
The argument of (-c) will run before the expression. In the rarer case that you need to run a statement after the main expression, you can use the (-C) flag.
Plot data you have access to from the command line using the pyplt alias:
alias pyplt='py -c '"'"'matplotlib.use(`Agg`); from matplotlib import pyplot as plt'"'"' -C '"'"'plt.savefig("output.jpg")'"'"
py '[math.sin(x/10) for x in range(100)]' | pyplt -l 'plt.plot(l)'
Fig1. - output.jpg
Download all the images from the front page of imgur:
curl http://imgur.com/ | py 'map(lambda _: _.attrs["src"].partition("//")[-1], bs4.BeautifulSoup(sys.stdin).findAll("img"))' | xargs -n1 wget >/dev/null 2>&1