Py学习  »  Python

使用map reduce job python生成的空输出文件

ThisisD • 4 年前 • 124 次点击  

我正在尝试执行一个简单的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)
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/47038
 
124 次点击