Павел Тысляцкий
* Убрать слайд после перехода на python 3.4
** Есть ньансы при которых окружения являются не абсолютно независимыми
from sh import *
# print wlan0 interface
print(ifconfig("wlan0"))
# checkout master branch
git.checkout("master")
# print the contents of this directory
print(ls("-l"))
# get the longest line of this file
longest_line = wc(__file__, "-L")
"""Usage: my_program.py [-hso FILE] [--quiet | --verbose] [INPUT ...] -h --help show this -s --sorted sorted output -o FILE specify output file [default: ./test.txt] --quiet print less text --verbose print more text """ from docopt import docopt if __name__ == '__main__': arguments = docopt(__doc__, version='my program 2.0') print(arguments)
>>> from pyquery import PyQuery as pq >>> from lxml import etree >>> import urllib >>> d = pq(url='http://google.com/', opener=lambda url, **kw: urllib.urlopen(url).read()) >>> d("#hello") [<p#hello.hello>] >>> p = d("#hello") >>> print(p.html()) Hello world ! >>> p.html("you know <a href='http://python.org/'>Python</a> rocks") [<p#hello.hello>] >>> print(p.html()) you know <a href="http://python.org/">Python</a> rocks >>> print(p.text()) you know Python rocks
Requests: HTTP for Humans
>>> r = requests.get('https://api.github.com', auth=('user', 'pass'))
>>> r.status_code 204
>>> r.headers['content-type'] 'application/json'
>>> r.text
...
class MySpider(CrawlSpider): name = 'example.com' allowed_domains = ['example.com'] start_urls = ['http://www.example.com'] rules = ( Rule(SgmlLinkExtractor(deny=('item\.php',))), Rule(SgmlLinkExtractor(allow=('item\.php',)), callback='parse'), ) def parse(self, response): sel = Selector(response) item = Item() item['id'] = sel.xpath('//td[@id="item"]/text()').re(r'ID: (\d+)') item['name'] = sel.xpath('//td[@id="item_name"]/text()').extract() return item
>>> from PIL import Image >>> im = Image.open("lena.ppm") >>> print(im.format, im.size, im.mode) PPM (512, 512) RGB
image = pdb.gimp_file_load('border.xcf', 'border.xcf')
layer = pdb.gimp_file_load_layer(image, 'content.xcf')
layer.set_offsets(5, 5)
image.add_layer(layer, 1)
merged_layer = image.merge_visible_layers(0)
image.scale(30, 36)
pdb.file_png_save2(image,merged_layer,'bi.png','bi.png',0,9,0,0,0,0,0,0,0)
gimp --no-interface --batch-interpreter python-fu-eval --batch "<PY BODY>"
http://pypi-ranking.info/alltime
http://pythonhackers.com/open-source
https://wiki.python.org/moin/UsefulModules