Graphviz AttributeError:对象没有属性“partition”

2024-09-29 01:22:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我在Django模型中使用graphviz为每个自动机呈现以下python脚本中的图形:

alphabets = automata.alphabet_set.all()
states = automata.states_set.all()
transitions = automata.transition_set.all()
dot = gv.Graph()
for state in states:
    dot.node(state.state, state.state)
for transition in transitions:
    dot.edge(transition.current_state, transition.next_state, transition.input)
dot.render( automata.id + '.gv', view=True)

这些是我的模型:

^{pr2}$

但每次我尝试执行脚本时,都会出现以下错误:

Traceback (most recent call last):
  File "make_graph.py", line 36, in <module>
    dot.edge(transition.current_state, transition.next_state, transition.input)
  File "/home/nids/automata/auto/lib/python3.5/site-packages/graphviz/dot.py", line 116, in edge
    tail_name = self.quote_edge(tail_name)
  File "/home/nids/automata/auto/lib/python3.5/site-packages/graphviz/lang.py", line 63, in quote_edge
    node, _, rest = identifier.partition(':')
AttributeError: 'States' object has no attribute 'partition'

我知道我没有错误,如果我只是这样做:dot.edge('A', 'B', 'edge label')


Tags: inpy模型脚本linealldotgraphviz
1条回答
网友
1楼 · 发布于 2024-09-29 01:22:53

graphvis代码希望传入一个字符串,而不是States对象(您的模型)。在

您可以在quote_edge函数的source code中看到这一点。在

相关问题 更多 >