您可以读取文件,然后写入某些特定行。
line_to_replace = 17 #the line we want to remplacemy_file = 'myfile.txt'with open(my_file, 'r') as file: lines = file.readlines()#now we have an array of lines. If we want to edit the line 17...if len(lines) > int(line_to_replace): lines[line_to_replace] = 'The text you want here'with open(my_file, 'w') as file: file.writelines( lines )
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)