0
我是新來的蟒蛇,並有一些問題,傳遞對象參數的多個inheritens傳遞參數 我有類圖與蟒蛇
class Graph:
def __init__(self,Name):
self.Name = Name
self.Nodes = {}
self.Edges = {}
def addEdgeAndNodes(self,sourceName,targetName): ''' code'''
def getEdgesCount(self):'''code '''
def getNodesCount(self):''' code '''
#some more code
和其他文件UpdateGraph類文件
import Graph
class UpdateGraph(Graph.Graph):
def __init__(self,Name):
super().__init__(Name)
def addUpdateEdgeAndNodes(self,sourceName,targetName,sourceType,targetType,edgeType):
#some more code
和GraphBuilder文件中:
from Graph import Graph
from UpdateGraph import UpdateGraph
class GraphDFS:
def __init__(self,graph):
self.Graph = graph
self.dfsRes = {}
def dfs(self):
#some code
print("-->"+self.Graph.getNodesCount())
#some code
class GraphBuilder:
def __init__(self):
self.Build()
def Build(self):
self.Graph = UpdateGraph(self.name)
def main():
Graph = GraphBuilder(name)
dfs = GraphDFS(Graph)
dfs.dfs()
main()
當我是試圖運行它引發錯誤的代碼: AttributeError的: 'GraphBuilder' 對象沒有屬性 'getNodesCount' 在行 打印( 「 - >」 + self.Graph.getNodesCount())
圖是updateGraph鍵入 我怎樣才能通過這個varible,它會通過圖形生成器功能來識別
顯然,'graph'是'GraphBuilder',不'UpdateGraph'對象,所以兩個問題的一個實例:什麼是'GraphBuilder' ,以及如何設置'graph'的值? – chepner
Graph Builder剛剛添加文本文件中的數據並生成圖形 – dima
顯示您構建'graph'對象的代碼 – qurban