Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9223367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:03:43+00:00 2026-06-18T04:03:43+00:00

So say I have this graph class Graph: def __init__(self): self.nodes =[] self.edges =

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T04:03:44+00:00Added an answer on June 18, 2026 at 4:03 am

    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

    import cmd
    
    class HelloWorld(cmd.Cmd):
        """Simple command processor example."""
    
        def do_greet(self, person):
            """greet [person]
            Greet the named person"""
            if person:
                print "hi,", person
            else:
                print 'hi'
    
        def do_EOF(self, line):
            return True
    
        def postloop(self):
            print
    
    if __name__ == '__main__':
        HelloWorld().cmdloop()
    

    Example

    $ python cmd_arguments.py
    (Cmd) help
    
    Documented commands (type help ):
    ========================================
    greet
    
    Undocumented commands:
    ======================
    EOF  help
    
    (Cmd) help greet
    greet [person]
            Greet the named person
    

    Again all from Dough Hellman πŸ˜€

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have this example graph, i want to find the edges connected to
Let's say I have this graph always a full graph one start node -
Lets say have this immutable record type: public class Record { public Record(int x,
Say i have this this structure. MyApp β”œβ”€β”€ main.py └── package β”œβ”€β”€ __init__.py β”œβ”€β”€
Say I have this class: class myclass { public int Field1{ get; set; }
Say I have a Graph class and a Vertex class, defined as below Graph.py
Let's say that I have a graph like this: A---B---C---D (master) \ \-E---F (HEAD)
Let's say I have a large (several thousand node) directed graph G and a
Say I have a graph (network) of nodes, with weightings on the following: 1.
I have a problem.... Lest say I have a class like this one: public

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.