-
virtualenv - A recipe to download and deploy Python 2.7 in your home directory without dependencies (except gcc)
-
-
-
def open_dash(filename,mode='r',bufsize=-1):
if filename == '-':
if 'w' in mode or 'a' in mode: return sys.stdout
elif 'r' in mode: return sys.stdin
else: raise Exception("Bad mode")
else:
return open(filename,mode,bufsize)
# allows you to put color codes in backticks and have them turned into escape codes
# example: colorize("`31`red `44`on blue`` reset")
# if enable is set to False, then backticked numbers are merely removed instead of being colorized
def colorize(s,enable=True): return re.sub('`(.*?)`','\x1b[\\1m',s) if enable else re.sub('`(.*?)`','',s)
# a decorator that puts the given function into a dictionary, changing its name:
heuristics = {}
def heuristic(func):
name = func.__name__.replace('gadget_is_','').replace('gadget_','').replace('_','-')
heuristics[name]=func
return func
def uniq(seq, idfun=None):
# order preserving
if idfun is None: idfun = lambda x: x
seen = {}
result = []
for item in seq:
marker = idfun(item)
if marker not in seen:
seen[marker] = 1
result.append(item)
return result
def product(L): return reduce(lambda x,y: x*y, L, 1)