applicative_functor

less info
101 reputation
3
bio website
location
age
visits member for 2 years
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'

This user has not answered any questions
This user has not asked any questions
This user has not participated in any tags
Stack Overflow 2,291 rep 1621
Programming Puzzles & Code Golf 111 rep 4
Ask Ubuntu 101 rep 3
Unix & Linux 101 rep 3
Code Review 101 rep 3

40 Votes Cast

all time   by type  
40 up 11 question
0 down 29 answer