Я получаю следующую ошибку, когда создаю экземпляр класса с помощью имеющегося у меня метода repr .
Когда я удаляю repr, он работает нормально:
repr удалено
class Wide():
def __init__(self, XfromLeftEdge = 141.0, YfromTopEdge = 300.0, Width = 1551.0, Height = 800.0 ):
self.XfromLeftEdge =XfromLeftEdge
self.YfromTopEdge =YfromTopEdge
self.Width = Width
self.Height = Height
def objOne(self): #XfromLeftEdge, YfromTopEdge, Width, Height
return XfromLeftEdge, YfromTopEdge, Width, Height
a = Wide()
print(a)
return:
<__main__.Wide object at 0x7faec1ed48b0>
(base) user SDNrig 6 %
с repr
class Wide():
def __init__(self, XfromLeftEdge = 141.0, YfromTopEdge = 300.0, Width = 1551.0, Height = 800.0 ):
self.XfromLeftEdge =XfromLeftEdge
self.YfromTopEdge =YfromTopEdge
self.Width = Width
self.Height = Height
def objOne(self): #XfromLeftEdge, YfromTopEdge, Width, Height
return XfromLeftEdge, YfromTopEdge, Width, Height
def __repr__(self):
return '{}, {}, {}, {}'.format(self.XfromLeftEdge = XfromLeftEdge, self.YfromTopEdge = YfromTopEdge, self.Width = Width, self.Height = Height)
def __str__(self):
return 'instance object of wide ROI object, XfromLeftEdge:{}, YfromTopEdge: {}, Width: {}, Height: {}'.format(
self.XfromLeftEdge = XfromLeftEdge,
self.YfromTopEdge = YfromTopEdge,
self.Width = Width,
self.Height = Height)
a = Wide()
print(a)
return
(base) user SDNrig 6 % /usr/local/bin/python3 "/Users/.../Desktop/SDNrig 6/play_f.py"
File "/Users/.../Desktop/SDNrig 6/play_f.py", line 15
return '{}, {}, {}, {}'.format(self.XfromLeftEdge = XfromLeftEdge, self.YfromTopEdge = YfromTopEdge, self.Width = Width, self.Height = Height)
^
SyntaxError: expression cannot contain assignment, perhaps you meant "=="?
Желаемый результат
Я бы хотел, чтобы print (a) дал параметры и их значения.