if you have a bad experience with someone, it's just him.
if you have a bad experience with everyone, it's you.
Mostly tech stuff
class sgd(type):
def __init__(cls, name, bases, dct):
overridden_bases = [ base for attr in dct.keys() for base in cls.__mro__ if hasattr(base, attr) and not attr.startswith('__') ]
required_methods = [ (base,m) for base in overridden_bases for m in base.__dict__ if m not in cls.__dict__ and not m.startswith('__') ]
if required_methods:
raise "unimplemented methods:", required_methods
super(sgd, cls).__init__(name, bases, dct)
class sgd_class(object):
__metaclass__ = sgd
>>> class a(sgd_class):
... def f(self): pass
... def g(self): pass
...
>>> class b(a): pass
...
>>> class c(a):
... def f(self): pass
... def g(self): pass
...
>>> class d(a):
... def f(self): pass
...
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "x.py", line 12, in __init__
if required_methods: raise "unimplemented methods:", required_methods
unimplemented methods:: [(<class '__main__.a'>, 'g')]
>>>
#read user password without displaying on screen
os.system("stty -echo")
print "Password:",
password = raw_input()
os.system("stty echo")
printWhat happens if the user changes her mind, and kills the program? All subsequent typing in the shell will be invisible! Checking for errors won't help here.finally cleanup block.finally clause for the stty echo.Someone should start a broad catalog of memes, not just pop-culture memes. Google book search shows our "capacity for self deception" going back to the 19th century.
Though it's easier to demonstrate this for criminals, it also applies to the best of us.
myseq[ m : n ]myseq[ m : n+1 ]myseq[ m-1 : n ]myseq[ m-1 : n+1 ]myseq[m].myseq[m:m]. Representing this with myseq[m:m-1] is clearly evil, and it breaks completely for m = 0.myseq[0:len(myseq)] is "nicer" than representing it as myseq[1:len(myseq)+1]. Perl doesn't even have this rationale :).find /some/path/. \( -type d -a \! -name . -prune \) -o -type f -printpartial(operator.add, 1) isn't such an attractive substitute for lambda x: x+1, but that's more about operator than it is about partial().partial()+1 should be supported using operator overloading. It'd be especially nice to be able to do partial()+x+y instead of partial(operator.add, x+y)try:
category, subject = headers['Subject'].split(':')
except:
category, subject = 'misc', headers['Subject']