applicative_functor

less info
101 reputation
3
bio website
location
age
visits member for 2 years
seen Apr 5 at 16:58
>>> 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'

This user has not asked any questions