pombreda / pydot

Automatically exported from code.google.com/p/pydot
MIT License
0 stars 0 forks source link

Non-string attribute (int) values break pydot #11

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. for a dot node, try node.set_fontsize(8), without the string quotes
2. write the graph to an external file 
3. pydot will break in some to_string routine

What is the expected output? What do you see instead?
I expected to have the int converted to string

I used a python int value when setting stuff:
node.set_fontsize(8)
has to be
node.set_fontsize("8")
I couldn't point my finger directly on where to put a good fix

Original issue reported on code.google.com by gerwinde...@gmail.com on 8 Apr 2008 at 11:09

GoogleCodeExporter commented 9 years ago
I've reproduced this error in the to_string() method of Edge.  The problem is 
with the following line:

  edge_attr.append( attr + '=' + quote_if_necessary(value) )

This problem can be elegantly fixed by making quote_if_necessary(x) return
  1) if x is a string, a quoted version of the
  2) if x is a number, str(x)
  3) if x is anything else, "%s" % str(x)

This will both address the problem as well as allow light serialization of 
lists, dictionaries, and such into 
GraphViz fields.

Original comment by dru...@gmail.com on 13 Dec 2009 at 7:59

GoogleCodeExporter commented 9 years ago
There is even simpler solution for that. The str function would be called
automatically on everything not being a string if instead of:
  edge_attr.append( attr + '=' + quote_if_necessary(value) )

you do just:
  edge_attr.append("%s=%s" % (attr, quote_if_necessary(value)))

Original comment by dupakrop...@googlemail.com on 14 May 2010 at 11:50

GoogleCodeExporter commented 9 years ago

Original comment by ero.carr...@gmail.com on 30 Oct 2010 at 5:33