Show default value for editing on Python input possible?

python input default value
python input default
python pre populate input
python if input is empty
prefill user input python
default input type in python
default value python variable
how to set a default value for a function in python

Is it possible for python to accept input like this:

Folder name: Download

But instead of the user typing "Download" it is already there as a initial value. If the user wants to edit it as "Downloads" all he has to do is add a 's' and press enter.

Using normal input command:

folder=input('Folder name: ')

all I can get is a blank prompt:

Folder name:

Is there a simple way to do this that I'm missing?


The standard library functions input() and raw_input() don't have this functionality. If you're using Linux you can use the readline module to define an input function that uses a prefill value and advanced line editing:

import readline

def rlinput(prompt, prefill=''):
   readline.set_startup_hook(lambda: readline.insert_text(prefill))
   try:
      return input(prompt)  # or raw_input in Python 2
   finally:
      readline.set_startup_hook()

Show default value for editing on Python input possible , Is it possible for python to accept input like this: Folder name: Download. But instead of the user typing "Download" it is already there as a initial value. If the user  Is it possible for python to accept input like this: Folder name: Download But instead of the user typing "Download" it is already there as a initial value. If the user wants to edit it as "Downloads" all he has to do is add a 's' and press enter.


I'm assuming you mean from the command-line. I've never seen initial values for command line prompts, they're usually of the form:

     Folder [default] : 

which in code is simply:

     res = raw_input('Folder [default] : ')
     res = res or 'default'

Alternatively, you can try to do something using the curses module in Python.

Providing 'default' value with raw_input()? - Python, Is it possible for python to accept input like this: Folder name: Download. But instead of the user typing “Download” it is already there as a initial  Show default value for editing on Python input possible? (6) I think that the best (the easiest and most portable) solution is a combination of @rlotun and @Stephen answers:


This works in windows.

import win32console

_stdin = win32console.GetStdHandle(win32console.STD_INPUT_HANDLE)

def input_def(prompt, default=''):
    keys = []
    for c in unicode(default):
        evt = win32console.PyINPUT_RECORDType(win32console.KEY_EVENT)
        evt.Char = c
        evt.RepeatCount = 1
        evt.KeyDown = True
        keys.append(evt)

    _stdin.WriteConsoleInput(keys)
    return raw_input(prompt)

if __name__ == '__main__':
    name = input_def('Folder name: ')
    print
    print name

Programming FAQ, Is it possible for python to accept input like this: Folder name: Download. But instead of the user typing "Download" it is already there as a initial  result = raw_input('['+str(default)+'] '+str(prompt)) if result == "": result = default return default I would like to include the ability to edit an existing value (drawn from an SQLite table) using a DOS console Python app, but my gut feeling from reading what I can find about raw_input() is that it only allows you to provide a prompt, not a default value as well.


I think that the best (the easiest and most portable) solution is a combination of @rlotun and @Stephen answers:

default = '/default/path/'
dir = raw_input('Folder [%s]' % default)
dir = dir or default

PyInquirer · PyPI, I'm wondering if it's possible, using raw_input(), to provide a 'default' value with the prompt? I would like to include the ability to edit an existing value (drawn from an allows you to provide a prompt, not a default value as well. If anyone but you can build that string any way you want, so it can show e.g., 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


I would like to suggest using the clipboard to solve this problem. Paste the clipboard into the input line, edit as required, press enter. Variable clpstack is used to protect existing clipboard contents. This code is for Windows. Linux could use import clipboard.

import pyperclip as clp
clpstack=clp.paste()
clp.copy("192.168.4.1")
HOST = input("Enter telnet host: ")
clp.copy(clpstack)

Edit Template Variables dialog - Help, When I edit an imported module and reimport it, the changes don't show up. In that case, it may not even be possible to import all of the modules at the top of the file. Instead, use None as the default value and inside the function, check if the For simple input parsing, the easiest approach is usually to split the line into  1 Answer 1. If your Python interpreter is linked against GNU readline, input() will use it. In this case, the following should work: Doesn't work on Mac OS X by default. Also, I had to change input() to raw_input() or it would throw "NameError: name 'what I typed' is not defined".


Function arguments - Manual, A Python module for collection of common interactive command line user interfaces, based on Inquirer.js. Defaults: input - Possible values: In Python, It is possible to get multiple values from the user in one line. i.e., In Python, we can accept two or three values from the user in one input() call. For example, in a single execution of the input() function, we can ask the user hi/her name, age, and phone number and store it in three different variables.


HTML DOM Input Hidden value Property, PyCharm | Preferences | Editor | Live Templates - Edit Variables for macOS In this field, specify the expression to have the value of the corresponding template input field calculated automatically. Predefined functions with possible arguments Note that a default value of a variable is an expression that can refer to other  How the input function works in Python : When input() function executes program flow will be stopped until the user has given an input. The text or message display on the output screen to ask a user to enter input value is optional i.e. the prompt, will be printed on the screen is optional.


PHP supports passing arguments by value (the default), passing by reference, echo "$input[0] + $input[1] = ", $input[0]+$input[1]; A function may define C++-​style default values for scalar arguments as follows: will coerce values of the wrong type into the expected scalar type if possible. echo $a['prop']; // shows: 2 Interactive Input Editing and History Substitution¶ Some versions of the Python interpreter support editing of the current input line and history substitution, similar to facilities found in the Korn shell and the GNU Bash shell. This is implemented using the GNU Readline library, which supports Emacs-style and vi-style editing. This library