使用Map Reduce作业Python生成的空输出文件

时间:2018-12-30 15:09:52

标签: python mapreduce

我正在尝试做一个简单的Map Reduce,但是正在生成一个空的输出文件。代码如下,我希望它对显示我想做的事情和诊断问题很有用

    # Initialise a list to store the top N records as a collection of touples (Wait.Time.month, record)
    myList = []
    n = 3   # Number of top N records

    for line in sys.stdin:
        # remove leading and trailing whitespace
        line = line.strip()
        # split data values into list
        data = line.split(",")

        # convert Wait.Time.month(currently an int) to int
        try:
            Wait.Time.month = int(data[7])
        except ValueError:
            # ignore/discard this line
            continue

        # add (Wait.Time.month, record) touple to list
        myList.append( (Wait.Time.month, line) )
        # sort list in reverse order
        myList.sort(reverse=True)

    # keep only first N records
    if len(myList) > n:
        myList = myList[:n]

# Print top N records
for (k,v) in myList:
    print(v)

0 个答案:

没有答案