答案 0 :(得分:0)
这取决于您想要如何访问它们,以下显示如何使用Python的CSV库完成它:
import csv
with open('corners_topsingle.csv', 'rb') as f_input:
csv_input = csv.reader(f_input)
data = []
for row in csv_input:
values = []
for value in row[2:]:
x, y = value.strip('()').split(',')
values.append((int(x), int(y)))
data.append(row[:2] + values)
print data
这会让你data
看起来像:
[['1', '02.jpg', (86, 54), (89, 454), (321, 76), (309, 418)],
['2', '03.jpg', (86, 54), (89, 454), (321, 76), (309, 418)],
['3', '04.jpg', (86, 54), (89, 454), (321, 76), (309, 418)]]
这假设您使用的是Python 2.x,并且您的CSV文件中的一行看起来像:
1,02.jpg,"(86,54)","(89,454)","(321,76)","(309,418)"
对于Python 3.x,请使用:
with open('corners_topsingle.csv', 'r', newline='') as f_input:
并更改为print(data)