MapReduce Amazon Python获取输入fi的行号

2024-10-06 06:44:46 发布

您现在位置:Python中文网/ 问答频道 /正文

我有几个文本,我想知道行号和文件中出现一个单词。在

我把文件弄得很好,但行号没有。在

这是地图

#!/usr/bin/env python

import sys
import os

find = 'but' #word to find
linesCont = 0

file = os.environ["map_input_file"]

for line in sys.stdin:
    line = line.strip()
    words = line.split()
    linesCont = linesCont + 1;  
    for word in words:
        if (word in (find)):        
            print '%s\t%s' % (file, linesCont)

而且是减少

^{pr2}$

事先非常感谢


Tags: 文件in文本importforossysline