在我的代码中,我有一个列表,其中包含多个具有不同扩展名的文件的路径。像这样的东西:
mylist = ['path1/file1.txt', 'path2/file2.dat', 'path3/file3.txt']
相反,我想制作一个包含此列表元素的外部文件,然后在我的代码中调用该文件。我该怎么办?
这很简单。
lines = []
with open("demofile.txt", "r") as f:
for line in f:
lines.append(line)
# Do whatever you were doing previously with the lines' list...