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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:44:22+00:00 2026-06-12T11:44:22+00:00

Possible Duplicate: Show default value for editing on Python input possible? I’d like to

  • 0

Possible Duplicate:
Show default value for editing on Python input possible?

I’d like to have a raw_input to ask for confirmation on something. Is there a way to have text already “entered” before the user types anything? For example:

>>> x = raw_input('1 = 2. Correct or incorrect? ', 'correct')
1 = 2. Correct or incorrect? correct

This could be compared to <imput type="text" value="correct"> in HTML. The text would be automatically typed for the user, but they could add to or erase all/part of it if they desire. Can this be done?

  • 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-12T11:44:23+00:00Added an answer on June 12, 2026 at 11:44 am

    Example 1:

    def make_question(question, *answers):
        print question
        print
        for i, answer in enumerate(answers, 1):
            print i, '-', answer
    
        print
        return raw_input('Your answer is: ') 
    

    Test code:

    answer = make_question('Test to correctness:', 'correct', 'not correct')
    print answer
    

    Outputs:

    Test to correctness:
    
    1 - correct
    2 - not correct
    
    Your answer is: correct
    correct
    

    Example 2:

    input = raw_input('Are you sure?: [Y]') # [Y] - YES by default
    if input.lower() in ['n', 'no']:
        exit() # or return...
    

    Example 3 (more complex):

    import termios, fcntl, sys, os
    
    def prompt_user(message, *args):
        fd = sys.stdin.fileno()
        oldterm = termios.tcgetattr(fd)
        newattr = termios.tcgetattr(fd)
        newattr[3] = newattr[3] & ~termios.ICANON & ~termios.ECHO
        termios.tcsetattr(fd, termios.TCSANOW, newattr)
        oldflags = fcntl.fcntl(fd, fcntl.F_GETFL)
        fcntl.fcntl(fd, fcntl.F_SETFL, oldflags | os.O_NONBLOCK)
    
        sys.stdout.write(message.strip())
        sys.stdout.write(' [%s]: ' % '/'.join(args))
    
        choice = 'N'
        lower_args = [arg.lower() for arg in args]
        try:
            while True:
                try:
                    c = sys.stdin.read(1)
                    if c.lower() in lower_args:
                        sys.stdout.write('\b')
                        sys.stdout.write(c)
                        choice = c
    
                    if c == '\n':
                        sys.stdout.write('\n')
                        break
    
                except IOError: 
                    pass
        finally:
            termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm)
            fcntl.fcntl(fd, fcntl.F_SETFL, oldflags)
    
        return choice
    

    Usage:

    print prompt_user('Are you sure?', 'Y', 'N', 'A', 'Q')
    

    Worked in Unix/Linux console (not from IDE)

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

Sidebar

Related Questions

Possible Duplicate: passing an empty array as default value of optional parameter in c#
Possible Duplicate: Android: ProgressDialog.show() crashes with getApplicationContext I want to have a progress dialog
Possible Duplicate: Show the original branch for a commit git version 1.7.4.1 I have
Possible Duplicate: JQuery Show hide class on hover just like stackoverflow, when you hover
Possible Duplicate: How to show/hide a div on mouseover using jquery? I have a
Possible Duplicate: “Least Astonishment” in Python: The Mutable Default Argument Okay, so basically I
Possible Duplicate: ActionLink to show parameters in URL instead of querystring? I have the
Possible Duplicate: Show ignored files in git I have forgotten how I setup my
Possible Duplicate: How to show only part of an int in c# (like cutting
Possible Duplicate: How to show Ajax requests in URL? Like in Gmail, using PHP

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.