擅长:python、mysql、java
<p>考虑文件名.txt包含创建多个.txt文件的所有单词。在</p>
<pre><code>f = open('fileNames.txt', 'r+')
for line in f:
if '\n' in line:
line = line[:-1] #assuming /n at the end of file
new = open("%s.txt"%line,"w+")
new.write("File with name %s"%line) #content for each file.
new.close()
</code></pre>
<p>如果字符串中\n存在,则不会创建新文件。因此要避免这种情况。
如果文件名.txt包含->青蛙四条腿<br/>
然后三个文件名为青蛙.txt四.txt以及腿.txt将被创建。在</p>