Mercurial > pylearn
annotate common/file.py @ 358:faece52be094
Added common.misc.runcmd
author | Joseph Turian <turian@iro.umontreal.ca> |
---|---|
date | Tue, 01 Jul 2008 21:09:24 -0400 |
parents | 430c9e92cd23 |
children | 9e84e8a20a75 |
rev | line source |
---|---|
355 | 1 import gzip, bz2 |
2 | |
3 def myopen(filename, mode="r", bufsize=-1): | |
4 """ | |
5 open(), detecting .gz and .bz2 file suffixes | |
6 """ | |
7 if filename[-3:] == ".gz": | |
8 return gzip.open(filename, mode, bufsize) | |
9 elif filename[-4:] == ".bz2": | |
10 return bz2.open(filename, mode, bufsize) | |
11 else: | |
12 return open(filename, mode, bufsize) |