Skip to content

read_dot bug (migrated from Trac #320) #317

Closed

Description

@networkx-trac

Original ticket https://networkx.lanl.gov/trac/ticket/320
Reported 2010-03-09 by smm, assigned to @hagberg.

I am trying to read a dot file that has every node name in quotes. pydot handles this correctly, but networkx doesn't in the read_dot in the nx_pydot file. Turns out you aren't handling quotes in the edge node names the same way you were in the node names.

if I make the following changes starting at line 105, it works.
(note this is a hand crafted approx of a diff, not the real thing)

-------- 8< ------------- start snip --------------8< --------------

  • def clean_name(n):

  •    n = n.strip() # removed whitespace
    
  •    if n.startswith('"') and n.endswith('"'):
    
  •        n = n[1:-1]
    
  •    return n
    
    • add nodes, attributes to N.node_attr

      for p in P.get_node_list():
  •    n=p.get_name()
    
  •    if n.startswith('"'):
    
  •        n = n[1:-1]
    
  •    n=clean_name(p.get_name())
    if n in ('node','graph','edge'):
        continue
    N.add_node(n,**p.get_attributes())
    

    add edges

    for e in P.get_edge_list():

  •    u=e.get_source()
    
  •    v=e.get_destination()
    
  •    u=clean_name(e.get_source())
    
  •    v=clean_name(e.get_destination())
    attr=e.get_attributes()
    N.add_edge(u,v,**attr)
    

-------- 8< ------------- end snip --------------8< --------------

up to you if you want the clean_name function in this function or available to the module. Also, in preview - looks like code is getting mangled. Email me if you want another copy.

Cheers

Sean

Activity

  1. networkx-trac commented on Jul 20, 2012

    @networkx-trac
    Author

    Comment in Trac by @hagberg, 2010-03-09

    (In [1553]) Strip double quotes from pydot node names if present.
    Fixes #320

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions