我在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')
graphvis
代码希望传入一个字符串,而不是States
对象(您的模型)。在您可以在
quote_edge
函数的source code中看到这一点。在相关问题 更多 >
编程相关推荐