无法删除标题,但未找到我的文件

时间:2016-12-01 22:54:31

标签: python-2.7 header user-defined-functions

我有这个主要的功能,在里面我有一个我定义为:

的removeHeader
def removeHeader (file_name):
     f = open(file_name).readlines()
     firstLine = f.pop(6)
     return firstLine

主要功能:

def readTasksFile(file_name):
    """Reads a file with a list of translation tasks into a collection.  
"""

    inFile = removeHeader(open(file_name, "r"))       

    tasksList = [] 
    for line in inFile:
        taskData = line.rstrip().split(", ")
        tasksList.append(taskData)        

    return tasksList

问题是,它找不到我的文件加上我非常确定removeHeader缺少一些东西,我已经看过一些关于删除已经在这里被问过的行的问题但是我没有&# 39;我真的很了解他们中的大多数人,因为现在大学新生我编程非常糟糕

1 个答案:

答案 0 :(得分:0)

In your removeHeader method you're trying open a file, but while calling the method removeHeader you're already passing the file handler. Replacing inFile = removeHeader(open(file_name, "r")) with inFile = removeHeader(file_name) in your readTasksFile should work