Ennol1
Ennol1

Reputation: 13

Is there a way to pre-write something after input?

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.)

Upvotes: 0

Views: 653

Answers (1)

Felix Jassler
Felix Jassler

Reputation: 1531

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']))

Upvotes: 1

Related Questions