所以我开始研究一个类并定义属性。后来,我尝试在函数中使用其中一个属性,我得到了
AttributeError: type object 'Curve' has no attribute 'a'
这是相关代码和截图:
class Curve:
def __init__(self, name: str, p: int, a: int, b: int, q: int, gx: int, gy: int, oid: bytes = None):
self.name = name
self.p = p
self.a = a
self.b = b
def is_point_on_curve(self, point: (int, int)) -> bool:
x, y, = point
left = y * y
right = (x * x * x) + (self.a * x) + self.b
return (left - right) % self.p == 0
我尝试在类的主体中添加属性(就像在 JAVA 中一样),但它不起作用。
我同意懒惰者的观点。您应该实例化 Curve 类的一个对象,然后您就可以访问它的属性和方法。
curve = Curve("mycurve", 2, 3, 4, 5, 6, 7)
x = curve.is_point_on_curve((2,2))
print(x)
我得到了
True