AttributeError: type object 'Point' has no attribute 'orientation'
AttributeError: type object 'Point' has no attribute 'orientation'
AttributeError:类型对象 'Point' 在 Python 包
中没有属性 'orientation'
包结构
Graph/
└── src/
└── Graph/
├── __init__.py
└── point.py
point.py
class Point:
def __init__(self, x, y):
self.x = x
self.y = y
def __str__(self):
return '('+str(self.x)+' , ' + str(self.y)+')'
@classmethod
def orientation(cls, p, q, r):
val = (float(q.y - p.y) * float(r.x - q.x)) - (float(q.x - p.x) * float(r.y - q.y))
if (val > 0):
return 1
elif (val < 0):
return 2
else:
return 0
_ init _.py
from .point import *
from Graph import Point
p1 = Point(1,1)
p2 = Point(2,2)
p3 = Point(3,2)
print(Point.orientation(p1,p2,p3))
AttributeError: 类型对象 'Point' 没有属性 'orientation'
使用 staticmethod
似乎工作正常
from __future__ import annotations
class Point:
def __init__(self, x: float, y: float):
self.x = x
self.y = y
def __str__(self) -> str:
return '(' + str(self.x) + ' , ' + str(self.y) + ')'
@staticmethod
def orientation(p: Point, q: Point, r: Point) -> int:
val = (float(q.y - p.y) * float(r.x - q.x)) - (float(q.x - p.x) * float(r.y - q.y))
if val > 0:
return 1
elif val < 0:
return 2
else:
return 0
p1 = Point(1, 1)
p2 = Point(2, 2)
p3 = Point(3, 2)
print(Point.orientation(p1, p2, p3))
AttributeError:类型对象 'Point' 在 Python 包
中没有属性 'orientation'包结构
Graph/
└── src/
└── Graph/
├── __init__.py
└── point.py
point.py
class Point:
def __init__(self, x, y):
self.x = x
self.y = y
def __str__(self):
return '('+str(self.x)+' , ' + str(self.y)+')'
@classmethod
def orientation(cls, p, q, r):
val = (float(q.y - p.y) * float(r.x - q.x)) - (float(q.x - p.x) * float(r.y - q.y))
if (val > 0):
return 1
elif (val < 0):
return 2
else:
return 0
_ init _.py
from .point import *
from Graph import Point
p1 = Point(1,1)
p2 = Point(2,2)
p3 = Point(3,2)
print(Point.orientation(p1,p2,p3))
AttributeError: 类型对象 'Point' 没有属性 'orientation'
使用 staticmethod
似乎工作正常
from __future__ import annotations
class Point:
def __init__(self, x: float, y: float):
self.x = x
self.y = y
def __str__(self) -> str:
return '(' + str(self.x) + ' , ' + str(self.y) + ')'
@staticmethod
def orientation(p: Point, q: Point, r: Point) -> int:
val = (float(q.y - p.y) * float(r.x - q.x)) - (float(q.x - p.x) * float(r.y - q.y))
if val > 0:
return 1
elif val < 0:
return 2
else:
return 0
p1 = Point(1, 1)
p2 = Point(2, 2)
p3 = Point(3, 2)
print(Point.orientation(p1, p2, p3))