0

I've been needing this for some time now, and i couldn't find a way to do it. I have a python script that uses python's input() function. And if you enter an argument inside of it, it writes something in front of the input, that means input("hi ") will output hi: in console, and after a space you can type in. But i don't want that, i want something that if you enter an argument it will pre-write something in the text. something like this:

input("enter a name: ", "name")

> enter a name: name
                ^^^^
                this is editable by user (can be deleted, modified, etc.)
  • 1
    You will need an advanced library like curses for this. – Michael Butscher Jul 11 '20 at 12:26
  • Please look here: https://stackoverflow.com/questions/2533120/show-default-value-for-editing-on-python-input-possible – Shlomo Gottlieb Jul 11 '20 at 12:27
  • 1
    There is a way, but it s not simple. You would have to not use `input`, but implement your own function which captures key press events and outputs them to the console. Then you could also control deleting the preselected option. – zvone Jul 11 '20 at 12:27

1 Answers1

1

If you're open for third-party libraries, have a look at PyInquirer. A simple example with a default input value that can be modified would look as follows:

from PyInquirer import prompt

question = [
    {
        'type': 'input',
        'name': 'first_name',
        'message': 'Name please',
        'default': 'Max'
    }
]

answer = prompt(question)
print('Hello {}'.format(answer['first_name']))
Felix Jassler
  • 1,029
  • 11
  • 22