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
430c9e92cd23 Added common directory
Joseph Turian <turian@iro.umontreal.ca>
parents:
diff changeset
1 import gzip, bz2
430c9e92cd23 Added common directory
Joseph Turian <turian@iro.umontreal.ca>
parents:
diff changeset
2
430c9e92cd23 Added common directory
Joseph Turian <turian@iro.umontreal.ca>
parents:
diff changeset
3 def myopen(filename, mode="r", bufsize=-1):
430c9e92cd23 Added common directory
Joseph Turian <turian@iro.umontreal.ca>
parents:
diff changeset
4 """
430c9e92cd23 Added common directory
Joseph Turian <turian@iro.umontreal.ca>
parents:
diff changeset
5 open(), detecting .gz and .bz2 file suffixes
430c9e92cd23 Added common directory
Joseph Turian <turian@iro.umontreal.ca>
parents:
diff changeset
6 """
430c9e92cd23 Added common directory
Joseph Turian <turian@iro.umontreal.ca>
parents:
diff changeset
7 if filename[-3:] == ".gz":
430c9e92cd23 Added common directory
Joseph Turian <turian@iro.umontreal.ca>
parents:
diff changeset
8 return gzip.open(filename, mode, bufsize)
430c9e92cd23 Added common directory
Joseph Turian <turian@iro.umontreal.ca>
parents:
diff changeset
9 elif filename[-4:] == ".bz2":
430c9e92cd23 Added common directory
Joseph Turian <turian@iro.umontreal.ca>
parents:
diff changeset
10 return bz2.open(filename, mode, bufsize)
430c9e92cd23 Added common directory
Joseph Turian <turian@iro.umontreal.ca>
parents:
diff changeset
11 else:
430c9e92cd23 Added common directory
Joseph Turian <turian@iro.umontreal.ca>
parents:
diff changeset
12 return open(filename, mode, bufsize)