0

我正在实现一个图形,并将一个 Route 类作为 Edge 类的子类。我试图在我的 Route 类中添加一个“距离”功能,所以我的 Route 类的构造函数覆盖了我的 Edge 类的构造函数。

由于它们位于不同的模块中,因此我在 Route 类中使用了“from Edge import *”;但是,程序(PyDev)仍然抛出错误,未定义变量:Edge

这是我的实现:

'''
An (directed) edge holds the label of the node where the arrow is coming from
and the label of the node where the arrow is going to
'''

class Edge:

    '''
    Constructor of the Edge class
    '''
    def __init__(self, fromLabel, toLabel):
        self.__fromLabel = fromLabel
        self.__toLabel = toLabel

    '''
    Get the label of the node where the arrow is coming from
    @return the label of the node where the arrow is coming from
    '''
    def getFromLabel(self):
        return self.__fromLabel

    '''
    Get the label of the node where the arrow is going to
    @return the label of the node where the arrow is going to
    '''
    def getToLabel(self):
        return self.__toLabel

from Edge import *

'''
A Route is inherited from the Edge class and is an edge specialized for the 
CSAirGraph class
'''

class Route(Edge):

    '''
    Constructor of the Route class
    '''
    def __init__(self, fromLabel, toLabel, distance):
        Edge.__init__(self, fromLabel, toLabel)
        self.__distance = distance

    '''
    Get the distance between two adjacent cities
    @return: the distance between two adjacent cities
    '''
    def getDistance(self):
        return self.__distance
4

0 回答 0