python读取TXT文件并逐行写入另外一个TXT文件

def TXTRead_Writeline(): 
    #读取文件
    ms = open("文件路径和全名")  
    #逐行写入
    for line in ms.readlines():  
        with open("要写入的文件路径和文件名","a") as mon:
            mon.write(line)  

例:读取C盘下面test文件夹下的base.txt文件逐行写入test.txt文件

def TXTRead_Writeline():   
    ms = open("c:\Test\base.txt")  
    for line in ms.readlines():  
        with open("c:\Test\test.txt","a") as mon:  
            mon.write(line)  
展开阅读全文

没有更多推荐了,返回首页