So say I have this graph
class Graph:
def __init__(self):
self.nodes =[]
self.edges = {}
def add_node(self,value):
self.nodes.append(value)
def is_node_present(self,node):
return True if node in self.nodes else False
Now what I want to do is something have user interact with this class..
Something like:
> g = Graph()
query executed
> g.add_node(2)
query executed
>g.is_node_present(2)
True
You know something like this.. (until user presses some secret button to quit)
How do i do this in python
Thanks
You want to look at http://docs.python.org/2/library/cmd.html as it handles the processing loop etc.
Dough Hellman http://www.doughellmann.com/PyMOTW/cmd/ is always a great resource of examples.
From Dough
Example
Again all from Dough Hellman π