python 中的 gzdecode 文件

gzdecode files in python

我使用这个有错误,我不明白

import glob
import zlib
import sys

for filename in sys.argv:
    with open(filename, 'r') as compressed:
        with open(filename + "-decompressed', 'w') as expanded:
        data = zlib.decompress(compressed.read())
        expanded.write(data)

错误

    with open(filename + "-decompressed', 'w') as expanded:
                                                          ^
SyntaxError: EOL while scanning string literal

您顺便用了一个双引号和一个单引号来关闭字符串。应该是

 with open(filename + '-decompressed', 'w') as expanded: