假设txt文件包含:
1 2 22
4 5 66
如何删除它的第一行。即1 2 22
答案 0 :(得分:0)
你可以这样做:
input_file = open('filename.txt')
output_file = open('output_filename.txt', 'w')
for line in input_file.readlines()[1:]:
output_file.write(line + '\n')
output_file.close()
使用单个文件相同:
input_file = open('filename.txt')
input_data = [line for line in input_file.readlines()]
input_file.close()
output_file = open('filename.txt', 'w')
for line in input_data[1:]:
output_file.write(line + '\n')
output_file.close()