我使用图文和Django模型为每个自动机呈现来自以下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)这些是我的模型:
class Automata(models.Model):
pass
class Alphabet(models.Model):
alphabet = models.CharField()
automata = models.ForeignKey(Automata, on_delete = models.CASCADE)
class States(models.Model):
state = models.CharField()
automata = models.ForeignKey(Automata, on_delete = models.CASCADE)
class Transition(models.Model):
current_state = models.ForeignKey(States, on_delete = models.CASCADE, related_name = 'current')
input = models.ForeignKey(Alphabet, on_delete = models.CASCADE)
next_state = models.ForeignKey(States, on_delete = models.CASCADE, related_name = 'next')
automata = models.ForeignKey(Automata, on_delete = models.CASCADE)但是,每次我尝试执行我的脚本时,我都会得到以下错误:
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')
发布于 2017-01-25 20:06:48
graphvis代码期望将一个字符串传递给它,而不是States对象(您的模型)。
您可以在源代码中的quote_edge函数中看到这一点。
https://stackoverflow.com/questions/41860513
复制相似问题