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?
In Python, Using the input() function, we take input from a user, and using the print() function, we display output on the screen. Using the input() function, users can give any information to the application in the strings or numbers format.
We can use the raw_input() function in Python 2 and the input() function in Python 3. By default the input function takes an input in string format. For other data type you have to cast the user input. In Python 3 we use the input() function which returns a user input value.
By default, inputs are stored as 'strings'. Therefore, we can use the map() function to indicate that the input will be converted into integers and then their values are stored in a variable.
Assuming you're using python 3. X, everything the user inputs will be a string.
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With