#!/usr/bin/env python # .pythonrc - brendan o'connor - anyall.org/code # need to set PYTHONSTARTUP=~/.pythonrc in shell to get this to run # from ipython: "execfile ~/.pythonrc" in ~/.ipython/ipythonrc # though __future__ statements dont work here: http://lists.ipython.scipy.org/pipermail/ipython-dev/2006-June/002250.html from __future__ import division import sys, os, atexit sys.path.insert(0,'/users/brendano/sw/py') sys.path.insert(0,'') # import rpy2.rpy_classic as rpy # rpy.set_default_mode(rpy.BASIC_CONVERSION) #import codecs; sys.stdout = codecs.open('/dev/stdout','w',encoding='utf8',buffering=0) #print "HEREHHRERE" try: __IPYTHON__ os.environ['PAGER'] = "less -r" except NameError: try: import readline except ImportError: print "Module readline not available." else: import rlcompleter readline.parse_and_bind("tab: complete") histfile = os.environ["HOME"] + "/.python_history" #looks like it and ipython will clobber each other #histfile = os.environ["HOME"] + "/.ipython/history" try: readline.read_history_file(histfile) except IOError: pass atexit.register(readline.write_history_file, histfile) del histfile # nice to have stdout unbuffered. but needs to be idempotent, tricky # instead: see fix_stdio() from anyall.org/util.py #if "" not in str(sys.stdout): # sys.stdout = os.fdopen(1,'w',0) ## I think it's nice to have lots of crap in the global namespace by default from urllib2 import urlopen import math import re from copy import copy, deepcopy from pprint import pprint from datetime import datetime, date, timedelta from collections import defaultdict import itertools from itertools import * import time import random import subprocess import cPickle as pickle import simplejson import xml.etree.ElementTree as ET ## tree = ET.parse(open("bla.xml")) for s in ( "from BeautifulSoup import BeautifulSoup", "from see import see", # github.com/inky/see "from lsv import lsv", # anyall.org/lsv.py ): try: exec s except ImportError, e: pass #print e del s def myjoin(seq, sep=" "): " because str.join() is annoying " return sep.join(str(x) for x in seq) def uniq_c(seq): ret = defaultdict(lambda:0) for x in seq: ret[x] += 1 return dict(ret) def stable_uniq(x): s = set(); y = [] for i in x: if i in s: continue s.add(i) y.append(i) return y def flatten(iter): return list(itertools.chain(*iter)) def flip(pairs): return [(y,x) for x,y in pairs] def xprod(xs,ys): for x in xs: for y in ys: yield (x,y) def mate(file): return subprocess.call(("mate", file)) def vim(file): return subprocess.call(("vim", file)) T = True F = False