TypeError:预期的str,bytes或os.PathLike对象,而不是list

时间:2017-10-25 03:37:50

标签: python

这是我的主要文件代码

import moduleA as moduleA
import os

filename1 = os.path.join(os.getcwd(),'script01.txt') 
filename2 = os.path.join(os.getcwd(),'script02.txt') 
myList1 = moduleA.get_file(filename1)
myList2 = moduleA.get_file(filename2)

这是我的moduleA代码

def get_file(filename):
    myList = []
    with open (filename) as filename:
        for line in filename:
            myList.append(line)
    return myList

我收到一条错误,说get_file中的open(filename)为filename:

TypeError: expected str, bytes or os.PathLike object, not list   

我检查过type(filename1)是字符串。我不知道哪里出错了

0 个答案:

没有答案