Skip to content

Instantly share code, notes, and snippets.

@thatmattbone
thatmattbone / blog_example.py
Created May 4, 2012
a tour of python's ElementTree path language
View blog_example.py
#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 Apr 28, 2011
exec() yourself silly
View exec_fun.py
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",
View lazily_evaluated_dict.py
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):
You can’t perform that action at this time.