Pydot错误,涉及解析“:"字符和数字 [英] Pydot Error involving parsing ':' character followed by number

查看:153
本文介绍了Pydot错误,涉及解析“:"字符和数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我在Anaconda的python 2.7中使用pydot,并注意到当我尝试在Pydot中使用某些字符串时,我不断收到错误消息.

So I was using pydot in python 2.7 from Anaconda and noticed I keep getting errors when I attempt to use certain strings in Pydot.

我隔离到的错误:

import pydot


graph = pydot.Dot(graph_type='digraph', rankdir = 'LR')
S = 'Total Flow Count ' + ':' + str(3)
legend = pydot.Node('Legend', label=S, shape='rectangle')

graph.add_node(legend)

每次运行此命令时,都会得到以下输出:

Whenever I run this I get the following output:

Traceback (most recent call last):
  File "path\of\my\code\errorisolate.py", line 13, in <module>
    graph.write_png('example5graph.png')
  File "c:\Anaconda\lib\site-packages\pydot.py", line 1609, in <lambda>
    lambda path, f=frmt, prog=self.prog : self.write(path, format=f, prog=prog))
  File "c:\Anaconda\lib\site-packages\pydot.py", line 1703, in write
dot_fd.write(self.create(prog, format))
  File "c:\Anaconda\lib\site-packages\pydot.py", line 1803, in create
status, stderr_output) )
InvocationException: Program terminated with status: 6. stderr follows: Error: c:\users\sidharth\appdata\local\temp\tmpxvwsls:3: syntax error near line 3

context: Legend [shape=rectangle, label=Total Flow Count >>>  : <<< 3];

到目前为止的分析/工作:

以某种方式将冒号:"后跟str()格式的数字组合似乎会引发错误.我尝试通过在前面附加'r'来修复它,因为我知道这是一种修复包含'\ n'字符的错误的方法.但是即使那样也没有运气.

Analysis/Work So Far:

Somehow the combination of a colon character ':' followed by a number in str() format seems to raise an error. I tried to fix it by append the 'r' in front since I know that is a way to fix errors invlving the '\n' character. But even then no luck.

我删除了r,因为它似乎引起了一些混乱.我一直使用r':'来模拟非编译换行符'\ n'的问题,因为pydot要求将它们列为r'\ n',其中r并未明确定义.

I removed the r as it appears to be causing a little confusion. I had kept r':' hoping to emulate the solution to the problem of non compiling newlines '\n', since pydot requires them to be listed as r'\n' where r is explicitly not defined.

按照:

Pydot在换行符上玩的不好吗?

推荐答案

我发现了这个问题编号38 -表示不能在节点名称或标签中使用特殊符号(例如冒号).它突出显示的原因是-

I found this issue number 38 - Which says we cannot use special symbols (like colon) in node names or labels. The reason it has highlighted is -

与问题28一样:节点名称中的冒号问题在于Graphviz 将使用它们来指定连接边缘的端口,这是一个Graphviz 神器. pydot支持它们的方式是允许它们以名称显示,如果您愿意的话 只需在名称中包含冒号字符,只需在字符串中添加引号即可.

As with issue 28: The problem with the colon in Node names is that Graphviz will use them to specify a port where to attach edges, it's a Graphviz artifact. The way pydot supports them is to allow them in names, if you wish to simply have colon characters in the name simply add quotes to the string.

例如:(注意实际字符串中的双引号):

For instance: (note the double quotes in the actual string):

node = pydot.Node('"Testnode:###@"')

print node.get_name()
'"Testnode:###@"'

尽管最好不要以自己的名字冒号.

Though you may be better off not having colon in your name.

这篇关于Pydot错误,涉及解析“:"字符和数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆