把文档全部作为一个字符串,字符串可以相加, 如在‘1.doc’里添加's' 和'd',用
>>>file=open('1.doc','r')
>>>string=file.read()
>>>string='s\n'+string+'\nd'
>>>file2=open('2.doc','w')
>>>file2.write(string)
file = open(r'test.txt', 'w')#用W模式打开文档
filetxt = "这里面的字符串将被写入到text.txt里面"
file.write(filetxt) #将filetxt的内容写入到file里面
file.close() #关闭文件
with open('text.txt','at') as handle:
handle.writelines(map(lambda ln: '%s\n'%ln,
tobewritelines))