Pydot没有打好换线?

时间:2014-06-26 23:59:22

标签: python png newline pydot

关闭蝙蝠 - 使用pydot 1.0.2的Ubuntu 12.04,python 2.7

我正在尝试让pydot将树打印到.png。我正在制作我的节点:

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

此处,cn以及fullstr只是字符串。

这很好,但是当我跑步时:

graph.write_png(output_path)

我收到以下错误(哎呀!) - 请在休息后继续关注

Traceback (most recent call last):
  File "Ant.py", line 47, in <module>
    f.makeOutput("output/ant", display=True)
  File "/home/aespielberg/ppr/ppr/svggen/library/api/component.py", line 322, in makeOutput
    self.makeComponentTree(filedir + "/tree.png")
  File "/home/aespielberg/ppr/ppr/svggen/library/api/component.py", line 267, in makeComponentTree
    graph.write_png(fn)
  File "/usr/lib/pymodules/python2.7/pydot.py", line 1602, in <lambda>
    lambda path, f=frmt, prog=self.prog : self.write(path, format=f, prog=prog))
  File "/usr/lib/pymodules/python2.7/pydot.py", line 1696, in write
    dot_fd.write(self.create(prog, format))
  File "/usr/lib/pymodules/python2.7/pydot.py", line 1796, in create
    status, stderr_output) )
pydot.InvocationException: Program terminated with status: 1. stderr follows: Warning: /tmp/tmpU5z0G8:2: string ran past end of line
Warning: /tmp/tmpU5z0G8:4: string ran past end of line
Error: /tmp/tmpU5z0G8:5: syntax error near line 5
context: Root >>>  -- <<<  "Root/front";
Warning: /tmp/tmpU5z0G8:6: string ran past end of line
Warning: /tmp/tmpU5z0G8:8: string ran past end of line
Warning: /tmp/tmpU5z0G8:10: string ran past end of line
Warning: /tmp/tmpU5z0G8:12: string ran past end of line
Warning: /tmp/tmpU5z0G8:14: string ran past end of line
Warning: /tmp/tmpU5z0G8:16: string ran past end of line
Warning: /tmp/tmpU5z0G8:18: string ran past end of line
Warning: /tmp/tmpU5z0G8:20: string ran past end of line
Warning: /tmp/tmpU5z0G8:22: string ran past end of line
Warning: /tmp/tmpU5z0G8:24: string ran past end of line
Warning: /tmp/tmpU5z0G8:26: string ran past end of line
Warning: /tmp/tmpU5z0G8:28: string ran past end of line
Warning: /tmp/tmpU5z0G8:30: string ran past end of line
Warning: /tmp/tmpU5z0G8:32: string ran past end of line
Warning: /tmp/tmpU5z0G8:34: string ran past end of line
Warning: /tmp/tmpU5z0G8:36: string ran past end of line
Warning: /tmp/tmpU5z0G8:38: string ran past end of line
Warning: /tmp/tmpU5z0G8:40: string ran past end of line
Warning: /tmp/tmpU5z0G8:42: string ran past end of line
Warning: /tmp/tmpU5z0G8:44: string ran past end of line
Warning: /tmp/tmpU5z0G8:46: string ran past end of line
Warning: /tmp/tmpU5z0G8:48: string ran past end of line
Warning: /tmp/tmpU5z0G8:50: string ran past end of line
Warning: /tmp/tmpU5z0G8:52: string ran past end of line
Warning: /tmp/tmpU5z0G8:54: string ran past end of line
Warning: /tmp/tmpU5z0G8:56: string ran past end of line
Warning: /tmp/tmpU5z0G8:58: string ran past end of line
Warning: /tmp/tmpU5z0G8:60: string ran past end of line
Warning: /tmp/tmpU5z0G8:62: string ran past end of line
Warning: /tmp/tmpU5z0G8:64: string ran past end of line
Warning: /tmp/tmpU5z0G8:66: string ran past end of line
Warning: /tmp/tmpU5z0G8:68: string ran past end of line
Warning: /tmp/tmpU5z0G8:70: string ran past end of line
Warning: /tmp/tmpU5z0G8:72: string ran past end of line
Warning: /tmp/tmpU5z0G8:74: string ran past end of line
Warning: /tmp/tmpU5z0G8:76: string ran past end of line
Warning: /tmp/tmpU5z0G8:78: string ran past end of line
Warning: /tmp/tmpU5z0G8:80: string ran past end of line
Warning: /tmp/tmpU5z0G8:82: string ran past end of line
Warning: /tmp/tmpU5z0G8:84: string ran past end of line
Warning: /tmp/tmpU5z0G8:86: string ran past end of line
Warning: /tmp/tmpU5z0G8:88: string ran past end of line
Warning: /tmp/tmpU5z0G8:90: string ran past end of line
Warning: /tmp/tmpU5z0G8:92: string ran past end of line
Warning: /tmp/tmpU5z0G8:94: string ran past end of line
Warning: /tmp/tmpU5z0G8:96: string ran past end of line
Warning: /tmp/tmpU5z0G8:98: string ran past end of line
Warning: /tmp/tmpU5z0G8:100: string ran past end of line
Warning: /tmp/tmpU5z0G8:102: string ran past end of line
Warning: /tmp/tmpU5z0G8:104: string ran past end of line
Warning: /tmp/tmpU5z0G8:106: string ran past end of line
Warning: /tmp/tmpU5z0G8:108: string ran past end of line
Warning: /tmp/tmpU5z0G8:110: string ran past end of line
Warning: /tmp/tmpU5z0G8:112: string ran past end of line
Warning: /tmp/tmpU5z0G8:114: string ran past end of line
Warning: /tmp/tmpU5z0G8:116: string ran past end of line
Warning: /tmp/tmpU5z0G8:118: string ran past end of line
Warning: /tmp/tmpU5z0G8:120: string ran past end of line
Warning: /tmp/tmpU5z0G8:122: string ran past end of line
Warning: /tmp/tmpU5z0G8:124: string ran past end of line
Warning: /tmp/tmpU5z0G8:126: string ran past end of line
Warning: /tmp/tmpU5z0G8:128: string ran past end of line
Warning: /tmp/tmpU5z0G8:130: string ran past end of line
Warning: /tmp/tmpU5z0G8:132: string ran past end of line
Warning: /tmp/tmpU5z0G8:134: string ran past end of line
Warning: /tmp/tmpU5z0G8:136: string ran past end of line
Warning: /tmp/tmpU5z0G8:138: string ran past end of line
Warning: /tmp/tmpU5z0G8:140: string ran past end of line
Warning: /tmp/tmpU5z0G8:142: string ran past end of line
Warning: /tmp/tmpU5z0G8:144: string ran past end of line
Warning: /tmp/tmpU5z0G8:146: string ran past end of line
Warning: /tmp/tmpU5z0G8:148: string ran past end of line
Warning: /tmp/tmpU5z0G8:150: string ran past end of line
Warning: /tmp/tmpU5z0G8:152: string ran past end of line
Warning: /tmp/tmpU5z0G8:154: string ran past end of line
Warning: /tmp/tmpU5z0G8:156: string ran past end of line
Warning: /tmp/tmpU5z0G8:158: string ran past end of line
Warning: /tmp/tmpU5z0G8:160: string ran past end of line
Warning: /tmp/tmpU5z0G8:162: string ran past end of line
Warning: /tmp/tmpU5z0G8:164: string ran past end of line
Warning: /tmp/tmpU5z0G8:166: string ran past end of line
Warning: /tmp/tmpU5z0G8:168: string ran past end of line

我是否在这一切中失去了你?还在我身边吗?

如果我删除换行符,它就能完美运行 - 没有错误。

所以我的问题是,如果换行符导致它像这样陷入困境,我怎么能换行?为什么换行会导致这样的错误开始?

1 个答案:

答案 0 :(得分:5)

"\n",换行符与r"\n",两个字符反斜杠和n之间存在差异。后者是raw string,对正则表达式特别有用。

至于为什么一个字符串有效而另一个字符串不起作用:pydot库是&#34; dumb&#34;,它只是为外部{{1}重新格式化命令服务。点击命令中间的换行符混淆了它,因此&#34;语法错误&#34;和其他问题。

这是修补后的代码:

dot