0

I want to prompt the user for an input via command line. I can do this with

time = raw_input("Enter a time (hh:mm): ")   # Python 2.x

or

time = input("Enter a time (hh:mm): ")   # Python 3

However, I would like to give the user an editable template, i.e. the command line should read:

Enter a time (hh:mm): 08:00

and the 08:00 should be editable. Now the user can hit enter and '08:00' is returned or he can change it to:

Enter a time (hh:mm): 08:45

to return '08:45'. Is anything like this possible?

Further info:

  • I use Linux with Python 2.7 (but other solutions are fine as well)

  • The prompt and the editable text can also be on separate lines.

  • I know that this particular example could be solved otherwise ("return for 08:00") but of course this is not so easy for what I actually want to do.

mathause
  • 1,607
  • 1
  • 16
  • 24
  • I do not believe it is possible. – sshashank124 Apr 01 '14 at 10:42
  • 1
    May be this is what you need. http://stackoverflow.com/questions/2533120/show-default-value-for-editing-on-python-input-possible – jitendra Apr 01 '14 at 10:49
  • you can try to implement this with [curses](https://docs.python.org/2/howto/curses.html) or manipulate `tty` with `termios` module. – m.wasowski Apr 01 '14 at 10:50
  • http://stackoverflow.com/questions/2533120/show-default-value-for-editing-on-python-input-possible does answer my question. Sorry for the duplicate, I did not find that one. – mathause Apr 01 '14 at 11:47

1 Answers1

0

For your case you can use print instead of editable input.

print("Enter a time (hh:mm): ",end="")

time=input()

print(time)

Community
  • 1
  • 1
HARDY8118
  • 622
  • 7
  • 15