view 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
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)