用类方法和静态方法实现:一个是追加写文件一行内容,一个是读指定行号的内容 #coding=utf-8 class handle_file(object): def __init__(self,file_path): self.file_path=file_path @classmethod def write_file(cls,file_path,content): with open(file_path,'a') as
方法可以有三个,但其实是一个方法,因为不同的方法都是文件存储的方法,文件修改就只有一个方法: 将文件导入list后,重新写入文件(另一个文件或者当前文件) 1.当前文件读取后,list修改内容,写入另一个新建文件 f = open("D:\data\k1.TXT","r") ff= open ("D:\data\\new\k1.TXT","w") new=[] for line in f: new.append(line) n