This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try: | |
from lxml import etree | |
except ImportError: | |
import xml.etree.ElementTree as etree | |
tree = lxml.etree.parse('file.xml') | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pickle | |
# write object to file | |
with open('entry.pickle', 'wb') as f: | |
pickle.dump(entry, f) | |
# read object from file | |
with open('entry.pickle', 'rb') as f: | |
entry = pickle.load(f) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# usage: | |
# >>> import pickleversion | |
# >>> with open('entry.pickle', 'rb') as f: | |
# ... v = pickleversion.protocol_version(f) | |
# >>> v | |
import pickletools | |
def protocol_version(file_object): | |
maxproto = -1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# get | |
import httplib2 | |
h = httplib2.Http('.cache') | |
response, content = h.request('http://diveintopython3.org/examples/feed.xml') | |
# post | |
from urllib.parse import urlencode | |
import httplib2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Standard awesome library | |
local gears = require("gears") | |
awful = require("awful") | |
awful.rules = require("awful.rules") | |
require("awful.autofocus") | |
-- Widget and layout library | |
local wibox = require("wibox") | |
-- Theme handling library | |
local beautiful = require("beautiful") | |
-- Notification library |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# Filename: raising.py | |
class ShortInputException(Exception): | |
'''A user-defined exception class.''' | |
def __init__(self, length, atleast): | |
Exception.__init__(self) | |
self.length = length | |
self.atleast = atleast | |
try: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# add this to the end of the module | |
if __name__ == "__main__": | |
import doctest | |
doctest.testmod() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from distutils.core import setup | |
setup( | |
name = "fibonacci", | |
packages = ["fib"], | |
version = "1.0", | |
description = "An generator for fibonacci series", | |
author = "Joseph Pan", | |
author_email = "cs.wzpan@gmail.com", | |
url = "http://hahack.com/", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
#### | |
# 02/2006 Will Holcomb <wholcomb@gmail.com> | |
# | |
# This library is free software; you can redistribute it and/or | |
# modify it under the terms of the GNU Lesser General Public | |
# License as published by the Free Software Foundation; either | |
# version 2.1 of the License, or (at your option) any later version. | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import MultipartPostHandler, urllib2, cookielib | |
cookies = cookielib.CookieJar() | |
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookies), MultipartPostHandler.MultipartPostHandler) | |
params = {"username": "bob", "password": "riviera", "file": open("filename", "rb")} | |
opener.open("http://wwww.bobsite.com/upload/", params) |