Mercurial > pylearn
view common/file.py @ 362:00d57d3f33eb
Added common.misc.utilsdir
author | Joseph Turian <turian@iro.umontreal.ca> |
---|---|
date | Thu, 03 Jul 2008 00:14:42 -0400 |
parents | 430c9e92cd23 |
children | 9e84e8a20a75 |
line wrap: on
line source
import gzip, bz2 def myopen(filename, mode="r", bufsize=-1): """ open(), detecting .gz and .bz2 file suffixes """ if filename[-3:] == ".gz": return gzip.open(filename, mode, bufsize) elif filename[-4:] == ".bz2": return bz2.open(filename, mode, bufsize) else: return open(filename, mode, bufsize)