目前,我有解压缩文件的代码,然后使用Popen将其压缩回另一个文件中
with open('./file.gz','rb') as in_file:
g_unzip_process = Popen(['gunzip','-c'],stdin=in_file,stdout=PIPE)
with open('./outfile.gz','wb+') as out_file:
Popen(['gzip'],stdin=g_unzip_process.stdout,stdout=out_file)
现在,我正在尝试在两者之间插入一些东西。
它应该像这样:
with open('./file.gz',stdout=PIPE)
transform_process = Popen(['python','transform.py'],stdin=transform_process.stdout,stdout=out_file)
我的transform.py代码看起来像这样
for line in sys.stdin:
sys.stdout.write(line)
sys.stdin.close()
sys.stdout.close()
运行后,为什么我的outfile.gz文件为空? 我还尝试通过运行以下内容来阅读每一行:
for line in transform_process.stdout:
print(line)
我如何做到使这些行写在outfile.gz中?