101 reputation
3
bio website
location
age
visits member for 2 years, 2 months
seen Mar 28 at 13:49
>>> from collections import defaultdict
>>> import json

>>> def tree(): return defaultdict(tree)

>>> t = tree()
>>> t['a']['b'] = 'foo'
>>> t['a']['c'] = 'bar'
>>> json.dumps(t)
'{"a": {"c": "bar", "b": "foo"}}'

.

>>> from operator import methodcaller
>>> methodcaller('__call__', 2, 10)(pow)
1024

.

>>> getattr(__import__('sys'), 'stdout').write('hello\n')

.

>>> class A(object):
...     pass
... 
>>> a = A()
>>> b = A()
>>> def foo(self):
...     print "foo"
... 
>>> import types
>>> a.foo = types.MethodType(foo, a)
>>> a.foo()
foo
>>> b.foo()
Traceback (most recent call last):
  File "<input>", line 1, in <module>
AttributeError: 'A' object has no attribute 'foo'

Dec
10
awarded  Autobiographer
Aug
23
awarded  Suffrage
Aug
23
awarded  Supporter