<分区> 分区>
我有一个代码可以从文件中读取信息(线描述点、多边形、线和圆)并将其解析为相应的类。 Point 有 x 和 7 坐标,Line 有起点和终点。
我有一个列表 (line = ['L1','L((1,1), (1,2))','# comment']) 我试着做它成一条线。问题在于创建终点,执行时出现以下错误 ValueError: invalid literal for int() with base 10: '' fr the variable x2
问题是什么?
代码:
def make_line(line):
name = line[0]
point = line[1].split(", ")
p = point[0].split(",")
x1 = int(p[0][3:])
y1 = int(p[1][:-1])
point1 = Point(x1,y1)
p = point[1].split(",")
x2 = int(p[0][1:])
y2 = int(p[1][:-2])
point2 = Point(x2,y2)
line = Line(point1,point2)
shapes[name] = line
