Pydot not playing well with line breaks?

前端 未结 1 606
情话喂你
情话喂你 2021-01-21 06:33

Off the bat - Ubuntu 12.04, python 2.7, using pydot 1.0.2

I\'m trying to get pydot to print a tree to a .png. I\'m making my nodes like so:

subnode = py         


        
1条回答
  •  醉梦人生
    2021-01-21 06:43

    There's a difference between "\n", a newline, vs r"\n", the two characters backslash and n. The latter is a raw string, and is especially useful for regular expressions.

    As to why one string works and the other doesn't: the pydot library is "dumb", it's just reformatting commands for an external dot service. The newline in the middle of commands to dot confuses it, thus the "syntax error" and other issues.

    Here's the patched code:

    subnode = pydot.Node(fullstr, label = c + r"\n" + n)
    graph.add_node(subnode)
    

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