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

  • Home
  • SEARCH
  • 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 8239251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:04:57+00:00 2026-06-07T20:04:57+00:00

I was asked to simulate CLI with Python. This is what I did def

  • 0

I was asked to simulate CLI with Python.

This is what I did

def somefunction(a,b):
    //codes here
//consider some other functions too

print "--- StackOverFlow Shell ---"
while True:
    user_input = raw_input("#> ")
    splitit = user_input.split(" ")
    if splitit[0] == "add":
        firstNum = splitit[1]
        sNum = splitit[2]
        result = somefunction(firstNum, sNum)
        print result
    //consider some other elif blocks with "sub", "div", etc
    else:
        print "Invalid Command"

I do also check the length of the list, here “splitit” I will allow only 3 argumets, first will be the operation, and second and third are the arguments with which some functions are to be performed, in case the argument is more than 3, for that i do put a check.

Though Somehow I manage to make it work, but is there a better way to achieve the same?

  • 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-07T20:04:59+00:00Added an answer on June 7, 2026 at 8:04 pm

    Use python CMD Module:

    Check few examples given on the below pages

    http://docs.python.org/library/cmd.html # Support for line-oriented command interpreters

    http://www.doughellmann.com/PyMOTW/cmd – # Create line-oriented command processors

    prompt can be set to a string to be printed each time the user is asked for a new command.

    intro is the “welcome” message printed at the start of the program.

    eg:

    import cmd
    
    class HelloWorld(cmd.Cmd):
        """Simple command processor example."""
    
        prompt = 'prompt: '
        intro = "Simple command processor example."
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Asked this first on serverfault, and someone recommended that I ask here. I'm looking
I recently asked this question about how to simulate type classes in D and
This question hasn't been asked yet. Some solutions probably have been proposed though to
I asked and answered a question here that is related to this issue and
Guys I have asked this question before but did not receive a single comment
I am not sure if this question has been asked here or not. I
Someone asked me about this and after reading some big O stuff I still
I have a project where I am asked to develop an application to simulate
I asked this question earlier and I got very quick and helpful responses: Linq
I asked a question before about VerticalRulers , with this hint I added a

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.