with open('full/path/to/file.txt') as file:
for line in file:
# Filter out any whitespace
line = line.replace(' ', '').strip()
# Split each line into a list containing two parts. The x coordinate
# and the y coordinate. Unpack the list into two variables.
xcoord, ycoord = line.split('|')
# Use the coordinates here
print(xcoord)
print(ycoord)
您只需迭代文件,并使用
str.split()
将字符串划分为两个单独的坐标:您可能还需要将两个坐标转换为整数,在这种情况下,可以执行以下操作:
^{pr2}$相关问题 更多 >
编程相关推荐