简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM