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 866779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:51:56+00:00 2026-05-15T09:51:56+00:00

Is there any short way to achieve what the APT ( Advanced Package Tool

  • 0

Is there any short way to achieve what the APT (Advanced Package Tool) command line interface does in Python?

I mean, when the package manager prompts a yes/no question followed by [Yes/no], the script accepts YES/Y/yes/y or Enter (defaults to Yes as hinted by the capital letter).

The only thing I find in the official docs is input and raw_input…

I know it’s not that hard to emulate, but it’s annoying to rewrite 😐

  • 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-05-15T09:51:57+00:00Added an answer on May 15, 2026 at 9:51 am

    As you mentioned, the easiest way is to use raw_input() (or simply input() for Python 3). There is no built-in way to do this. From Recipe 577058:

    import sys
    
    
    def query_yes_no(question, default="yes"):
        """Ask a yes/no question via raw_input() and return their answer.
    
        "question" is a string that is presented to the user.
        "default" is the presumed answer if the user just hits <Enter>.
                It must be "yes" (the default), "no" or None (meaning
                an answer is required of the user).
    
        The "answer" return value is True for "yes" or False for "no".
        """
        valid = {"yes": True, "y": True, "ye": True, "no": False, "n": False}
        if default is None:
            prompt = " [y/n] "
        elif default == "yes":
            prompt = " [Y/n] "
        elif default == "no":
            prompt = " [y/N] "
        else:
            raise ValueError("invalid default answer: '%s'" % default)
    
        while True:
            sys.stdout.write(question + prompt)
            choice = input().lower()
            if default is not None and choice == "":
                return valid[default]
            elif choice in valid:
                return valid[choice]
            else:
                sys.stdout.write("Please respond with 'yes' or 'no' " "(or 'y' or 'n').\n")
    

    (For Python 2, use raw_input instead of input.)
    Usage example:

    >>> query_yes_no("Is cabbage yummier than cauliflower?")
    Is cabbage yummier than cauliflower? [Y/n] oops
    Please respond with 'yes' or 'no' (or 'y' or 'n').
    Is cabbage yummier than cauliflower? [Y/n] [ENTER]
    >>> True
    
    >>> query_yes_no("Is cabbage yummier than cauliflower?", None)
    Is cabbage yummier than cauliflower? [y/n] [ENTER]
    Please respond with 'yes' or 'no' (or 'y' or 'n').
    Is cabbage yummier than cauliflower? [y/n] y
    >>> True
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Short version: Is there way to achieve in Python the same effect achieved by
Is there any way to do things the short and easy way like below?
For Postgres is there any sort of command line utilities that allow a database
Is there any way to add any sort of debugging to a Lego Mindstorms
Is there any EASY way to sort an array in descending order like how
Is there any standard way of implementing some sort of a write-through buffer for
When using linq and you have c.Sort() Is there any good inline way of
Is there any short syntax for if-else statement in objective C like PHP: if($value)
Is there any keyboard short cut to compile selected file in C++ project in
Is there any Java profiler that allows profiling short-lived applications? The profilers I found

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.