从一份txt文档中提取每一行的字符串,然后分别以提取的字符串作为文件名新建一份txt文档

从一份txt文档中提取每一行的字符串,然后分别以提取的字符串作为文件名新建一份txt文档,像这样,假设a.txt,第一行是1,第二行是2,第三行是3.........然后就分别建立1.txt,2.txt,3....

请将#替换为空格,代码如下:

filename = "a.txt"
with open(filename, "r") as fpr:
####for line in fpr:
########with open(line.strip() + ".txt", "w") as fpw:
############fpw.write(line)追问

有bat批处理的吗?

追答

for /f "tokens=*" %%i in (a.txt) do (echo %%i>%%i.txt)

温馨提示:答案为网友推荐,仅供参考
相似回答