Passing a string to agedge in agraph.py. Issue with networkx and pygraphviz

后端 未结 1 885
小鲜肉
小鲜肉 2020-12-28 13:44

Given this initial graph:

import networkx as nx
G=nx.MultiGraph()
fromnodes=[0,0,1,1,1,1,1,2,3,4,5,5,5,7,8,9,10]
tonodes=[1,1,2,3,4,5,6,7,8,9,10,11,12,13,14,         


        
相关标签:
1条回答
  • 2020-12-28 14:32

    Try changing the variable name from "key" to something else like "temp_key". I mean that it is possible that you (or any previously imported module) has declared a non-string type "key" variable before...?

    Apparently if running :

    eh = gv.agedge(self.handle, uh, vh, key , _Action.create)
    

    fails but running:

    eh = gv.agedge(self.handle, uh, vh, "key" , _Action.create)
    

    give you no issue, it could only be relative to the "key" variable type.. did you try this:

    eh = gv.agedge(self.handle, uh, vh, str(key) , _Action.create)
    

    or eh = gv.agedge(self.handle, uh, vh, unicode(key) , _Action.create)

    Integrate str()/unicode() in your orginal code give:

    import networkx as nx
    G=nx.MultiGraph()
    fromnodes=[0,0,1,1,1,1,1,2,3,4,5,5,5,7,8,9,10]
    tonodes=[1,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]
    dupedgeind=0
    for x,y in zip(fromnodes,tonodes):
        if G.has_edge(x,y):
            dupedgeind=dupedgeind+1
            G.add_edge(x,y,key=str(dupedgeind))
            #G.add_edge(x,y,key=unicode(dupedgeind))
        else:
            dupedgeind=0
            G.add_edge(x,y,key=str(dupedgeind))
            #G.add_edge(x,y,key=unicode(dupedgeind))
    

    both (str & unicode version) works fine on Linux.

    Best regards

    0 讨论(0)
提交回复
热议问题