如何将空格分隔的文件转换为制表符分隔的文件?



我有两个数据文件,即'fin.dat'和'shape.dat'。我想格式化'shape.dat',就像用Python编写'fin.dat'一样。这些文件可以在这里找到https://easyupload.io/m/h94wd3。这里给出了数据结构的片段fin. data,shape.dat。请帮我做这件事。

with open('shape.dat') as fin, open('new.dat', 'w') as fout:
#to have data in separate columns from a single column
for line in fin:
fout.write(line.replace('t', ','))
嗨,Hirak,试试上面的代码。这在我的系统里起作用了。下面是操作 后的输出

最新更新