从python中的单个文件读取多个文件的路径

问题描述 投票:-1回答:1

在我的代码中,我有一个列表,其中包含多个具有不同扩展名的文件的路径。像这样的东西:

mylist = ['path1/file1.txt', 'path2/file2.dat', 'path3/file3.txt']

相反,我想制作一个包含此列表元素的外部文件,然后在我的代码中调用该文件。我该怎么办?

python list readfile
1个回答
0
投票

这很简单。

    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...
© www.soinside.com 2019 - 2024. All rights reserved.