我想创建基于列表的批量文本文件。文本文件包含多行/标题,目标是创建文本文件。以下是我的titles.txt与非工作代码和预期输出的关系。Python空白txt文件创建
titles = open("C:\\Dropbox\\Python\\titles.txt",'r')
for lines in titles.readlines():
d_path = 'C:\\titles'
output = open((d_path.lines.strip())+'.txt','a')
output.close()
titles.close()
titles.txt
Title-A
Title-B
Title-C
new blank files to be created under directory c:\\titles\\
Title-A.txt
Title-B.txt
Title-C.txt
只是一个建议:你可能想用[os.path.join()](http://docs.python.org/library/os.path.html#os.path.join)代替字符串连接和strip()等 – Levon
而不是追加,也许你应该打开“W”选项? –
(1)你的问题是什么? (2)你确定'd_path.lines.strip()'的语法吗?你想连接一些字符串吗? –