jake RSS


jakehofman.com

Archive

Oct
12th
Mon
permalink

tip: python

to create a nested defaultdict of defaultdicts, use d = defaultdict(lambda : defaultdict(int)) http://bit.ly/tUbev

tips  python 
Jul
28th
Tue
permalink

tip: python

return rows as dicts with mysqldb using the DictCursor class http://bit.ly/56bBm

tips  python 
Jun
16th
Tue
permalink

tip: python

use a join wrapped around a list comprehension for fast string appends http://bit.ly/K4vsr

tips  python 
Jun
9th
Tue
permalink

tip: python

quick fix to print with unicode characters replaced by ?: print repr(uni.encode(‘ascii’,’replace’)) http://bit.ly/kT4KX

tips  python 
permalink

tip: python

use codes.open(filename,mode,encoding) to read/write with transparent encoding/decoding for, e.g. unicode http://bit.ly/16mfnU

tips  python 
permalink

tip: python

use dir(x) or x.__dict__.keys() to get a list of fields an object or module defines http://bit.ly/UAVN

tips  python 
May
26th
Tue
permalink

tip: python

use the tempfile module to generate temporary files and directories http://bit.ly/IuEMU

tips  python 
May
18th
Mon
permalink

tip: python

use optparse as an advanced alternative to getopts for options parsing http://bit.ly/MaYfq

tips  python 
permalink

tip: python

use StringIO (unicode, slower) and cStringIO (ascii only, faster) to treat strings as file streams http://bit.ly/Aqf2y

tips  python 
Apr
7th
Tue
permalink

tip: python

use os.path functions split, splitext, join, etc. for manipulating file paths http://bit.ly/85qWo

tips  python