Created
August 5, 2014 04:50
-
-
Save whosaysni/2e3398bef09289be438a to your computer and use it in GitHub Desktop.
Zとgzに対応する: loading both Z/gz compressed file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 汚くて発狂しそう | |
def open_zfiles(filename): | |
open_method = open # builtin open | |
if filename.endswith('gz'): | |
open_method = gzip.open # gzip's open | |
elif filename.endswith('Z'): | |
from subprocess import Popen, PIPE | |
open_method = lambda fn: Popen(['zcat', fn], stdout=PIPE).stdout | |
with open_method(filename, 'rb') as infile: | |
return infile |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment