我有一个包含以下表格中数据的文件:
Foo
http://url.com
http://url2.com
FooBar
http://url3.com
FooBarBar
http://url9.com
我想把每n行分别当作一个元素。因此,在每一行只有一个\n
之后,我想处理以下字符串和url(url的数量各不相同)。我用第一个字符串的名称创建一个文件夹,然后从URL下载文件。你知道吗
我使用下面的行来获取行的列表。你知道吗
elements = list(open('C:\\filename.txt'))
现在我想把它放到一个列表列表中,\n
用作分隔符元素。你知道吗
我怎样才能达到我想要的?你知道吗
由于您没有关闭文件,因此不应在这类问题中出现一行:
输出:
迭代方法根据要求创建一个带有第一个字符串名称的文件夹,然后从URL下载文件
您应该能够遍历文件中的行,并分别处理每种情况。你知道吗
输出:
这将允许您使用结果创建目录并下载每个列表中的文件,例如:
输出:
相关问题 更多 >
编程相关推荐