我一直在修改一些坐标,我想互相检查一下。
我有一个标签文件,它由6列组成。这是我要减去的最后4列,在最后一个坐标列之后的两列中得到结果。也"选项卡"。
我想对相当大的文件这样做,这可能吗?如果没有,我怎么用小文件来做呢?我读了一些资料,发现csv模块到处都是。
<>之前337905.44 5269907.69 337905.38 5269907.78337917.95 5269907.55 337917.93 5269907.62337930.46 5269907.34 337930.48 5269907.46337942.97 5269907.13 337942.84 5269907.06之前当我放弃时,这就是我走了多远;
import csv
with open('coor.txt', newline='') as f:
reader = csv.reader(f, delimiter=':', quoting=csv.QUOTE_NONE)
To sum up, all I want to do is to have the first and third column subtracted, and the second and fourth column subtracted, and get the difference in two columns after the last coordinate column.
Thanks in advance!
Something like this?
#!/usr/bin/env python
with open('input') as fd:
for line in fd:
columns=line.split()
columns=map(float,columns)
print "%s | t %s t %s" % (line.strip(), columns[0] - columns[2],
columns[1] - columns[3])
输出337905.44 5269907.69 337905.38 5269907.78 | 0.0599999999977 -0.089999999851
337917.95 5269907.55 337917.93 5269907.62 | 0.0200000000186 -0.070000000298
337930.46 5269907.34 337930.48 5269907.46 | -0.0199999999604 -0.120000000112
337942.97 5269907.13 337942.84 5269907.06 | 0.129999999946 0.070000000298
使用csv-module
:
import csv
with open('input', 'rb') as fd:
reader=csv.reader(fd,delimiter='t')
for row in reader:
#your calculations
print row