python reads the coordinate method in the text
- 2020-12-13 19:02:07
- OfStack
Using python to read text files is very convenient, using the string module, the following uses a small example to demonstrate reading the coordinate information in the text.
import string
x , y , z = [] , [] ,[]
with open("test.txt") as A:
for eachline in A:
tmp = eachline.split()
x.append(string.atof(tmp[0]))
y.append(string.atof(tmp[1]))
z.append(string.atof(tmp[2]))
print x,y,z
The text is as follows:
0.1 0.2 1
0.3 0.4 2
0.4 0.5 3
0.6 0.7 4
Since you are reading on a row basis, you can use split() to split the read string and then convert it to a number.