101 reputation
1
bio website katriel.co.uk
location Cambridge, United Kingdom
age 22
visits member for 2 years, 8 months
seen Dec 15 '10 at 16:50
stats profile views 0
>>> class Oops(object):
...     def __init__(self):
...             Oops.__call__ = self
... 
>>> x = Oops()
>>> x()

>>> Z = lambda f: (lambda x: f(lambda *args: x(x)(*args)))(lambda x: f(lambda *args: x(x)(*args)))
>>> fact = Z(lambda f: lambda x: 1 if x == 0 else x * f(x-1))
>>> fact(5)
... 120

>>> 0 < 0 == 0
... False

def foo():
    return
    yield

raise TypeError() from ValueError()

def spam(*, ham):
    pass

Move code from try to else if you don't want to catch any errors that it produces.

try:
    do_not_do_this_at_home()
except ToldYouSo:
    die()
else:
    whaddyaknow()
finally:
    cleanup()

Yowza!

>>> class attrdict(dict):
...   def __init__(self, *args, **kwargs):
...     dict.__init__(self, *args, **kwargs)
...     self.__dict__ = self

Easy dynamic programming in Python 3.2:

@functools.lru_cache(maxsize=None)
def fib(n):
    if n < 2: return n
    return fib(n-1) + fib(n-2)

This user has not answered any questions
This user has not participated in any tags
This user has not asked any questions
Stack Overflow Stack Overflow 31,299 rep 43078
Super User Super User 156 rep 16
TeX - LaTeX Stack Exchange TeX - LaTeX 133 rep 4
Meta Stack Overflow Meta Stack Overflow 112 rep 14
Seasoned Advice Seasoned Advice 108 rep 3

0 Votes Cast

This user has not cast any votes