[英]how to read text file each tuples and integers are splited properly
I have a text file (target file of NWPU VHR-10 dataset) that included 2 tuples and one integer for each line eg each line has the text like this:我有一个文本文件(NWPU VHR-10 数据集的目标文件),其中每行包含 2 个元组和一个 integer,例如,每一行的文本如下:
(563,478),(630,573),1 (563,478),(630,573),1
Now I wanna find out how to split and read it like two tuples and one integer.现在我想了解如何像两个元组和一个 integer 一样拆分和读取它。 eg:
例如:
tuple 1: (563,478) tuple 2: (630,573) int: 1元组 1:(563,478) 元组 2:(630,573) 整数:1
thanks谢谢
thanks for @mkrieger1 the solution I found was this感谢@mkrieger1 我找到的解决方案是这样的
import re
for line in target_file:
line = re.sub(r"([()])", "", line)
lst = list(map(int, line.split(',')))
k, t, p = (lst[0], lst[1]), (lst[2], lst[3]), lst[4]
print(k)
print(t)
print(p)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.