我想学习一点Python,我的目标是打开gzip file
,输入搜索查询然后打印出来,最终将结果输出到文件中。在Python中集成grep
import gzip
file = raw_input('Input Filepath: ') # input file path
with gzip.open(file, 'rb') as f: # opens gzip fil .gz
file_content = f.read() # reads the contents
grep = raw_input('Enter Search: ') # grep asks for output
print(file_content) # prints it in console
我也试过用print(file_content, grep)
,但它只返回第一个查找。
请包括您的文件内容的示例以及给定grep值的预期输出。 – ettanany
不知道你在这里试图做什么。 'grep'是一个命令行工具。你想在这里复制它的行为吗? –
@ettanany我想打开gz文件,然后输出我在“搜索”中输入的信息我想用grep,因为我知道/知道如何才能得到结果 – JJWatt