[英]how to delete the first and third column from a text file in python
所以我想删除这个文本文件的第一和第三列我的文本文件看起来像这样:
1 2 3
4 5 6
我想用python删除第一列和第三列。
我的代码如下所示:
f = open("5.txt", "r")
g = open("datafile_fixed.txt", "w")
for line in f:
if line.strip():
g.write("\t".join(line.split()[1:]) + "\n")
f.close()
g.close()
但我只能删除第一列。 如何删除第一和第三?
尝试:
g.write("\t".join(line.split()[1:-1]) + "\n")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.