在指定位置插入新行
line_number = 3 # 插入行的位置
new_line = "This is a new line"
content.insert(line_number-1, new_line) # 在指定位置插入新行
with open(filename, "w") as file:
file.writelines(content) # 将更新后的内容写入文件
在指定位置插入新行
line_number = 3 # 插入行的位置
new_line = "This is a new line"
content.insert(line_number-1, new_line) # 在指定位置插入新行
with open(filename, "w") as file:
file.writelines(content) # 将更新后的内容写入文件