Skip to content

Instantly share code, notes, and snippets.

@thatmattbone
thatmattbone / blog_example.py
Created May 4, 2012 01:04
a tour of python's ElementTree path language
#from thatmattbone.com
import sys
import trace
import xml.etree.ElementTree
from xml.etree.ElementPath import prepare_child, xpath_tokenizer
TEST_DOC = """
<root>
<a>
<b value="2"/>
@thatmattbone
thatmattbone / exec_fun.py
Created April 28, 2011 02:19
exec() yourself silly
import random
class AreYouFeelingLuckyDict(dict):
"""A dictionary with a 50% chance of returning the thing you
actually put into it."""
exclude = set(["runs",
"NameError",
"True",
"random",
class LazyDictionary(object):
def __init__(self, callback=dict):
self.data = None
self.callback = callback
def evaluate_callback(self):
self.data = self.callback()
def __getitem__(self, name):