Python读取文件内容后将内容分组创建文件,写入对应的文件内容
def output(filename):
new_file_line = []
with open(filename,'r') as fe:
names = fe.readlines()
for new_list in names:
new_file_line.append(new_list.replace('\n',''))
print(new_file_line) #打印数组内容
for list_cont in new_file_line: #遍历数组
with open(list_cont+'.txt','w') as new_file_cont: #将数组中的元组创建成文件名
for i in list_cont: #遍历数组中元组的内容
new_file_cont.write(i +'\n') #将元组中的内容写入创建的文件中
output('word.txt')




浙公网安备 33010602011771号