diff common/file.py @ 355:430c9e92cd23

Added common directory
author Joseph Turian <turian@iro.umontreal.ca>
date Thu, 19 Jun 2008 16:12:29 -0400
parents
children 9e84e8a20a75
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/common/file.py	Thu Jun 19 16:12:29 2008 -0400
@@ -0,0 +1,12 @@
+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)