Python:导入后父类仍然是一个未定义的变量

时间:2012-10-11 09:11:47

标签: python

我正在实现一个图,我将一个Route类作为Edge类的子类。我尝试在Route类中添加“距离”功能,因此我的Route类的构造函数会覆盖Edge类的构造函数。

由于它们位于不同的模块中,我在Route类中使用了“from edge import *”;但是,程序(PyDev)仍然会抛出错误,Undefined variable: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

0 个答案:

没有答案