Re: Default/editable string to raw_input




Paraic Gallagher wrote:
Hi,

This is my first post to the list, I hope somebody can help me with this
problem. Apologies if it has been posted before but I have been internet
searching to no avail.

What I am trying to do is provide a simple method for a user to change a
config file, for a test suite.
The config file consists of a number of keys, eg. build number, target
device, etc.

What I would like to do is give the user a key, and the previous value
for that key.
The user can then accept the previous value or edit it on the line.

I have a method where the previous value of a key is presented to the
user and can be accepted if the user hits return. But as some of the
values are somewhat long, and the user may only need to change 1 or 2
characters, it would be a nice feature to offer line editing.

I can get the readline.set_pre_input_hook() function to send text after
a raw_input prompt, but this text cannot be edited.

With the disclaimer that, as others have said, this may not be the best
user-interface choice:

import readline
readline.set_startup_hook(lambda: readline.insert_text(old_value))
try:
new_value = raw_input()
finally:
readline.set_startup_hook(None)

Note that, among other issues, this isn't threadsafe (but then, you
really shouldn't be doing console I/O from multiple threads anyway).
Hope this helps.

-- David

.



Relevant Pages

  • Default/editable string to raw_input
    ... This is my first post to the list, I hope somebody can help me with this problem. ... Apologies if it has been posted before but I have been internet searching to no avail. ... What I am trying to do is provide a simple method for a user to change a config file, ... The config file consists of a number of keys, eg. build number, target device, etc. ...
    (comp.lang.python)
  • Re: Location of my xf86config file
    ... >> Tried man XFree86 as well before my first post. ... Or maybe the permissions aren't correct. ... config file that is writable other than by its owner. ...
    (alt.os.linux)
  • Re: Djikstra counting semaphore in c# for your review
    ... "TT (Tom Tempelaere)" wrote: ... I did post a few changes after the first post. ... Throwing pulls you out of the context in which the ... The only sad thing about Debug.Assert's in MT code is that they may trigger from multiple threads and that can become messy if one assert is directly followed by another from another thread. ...
    (microsoft.public.dotnet.languages.csharp)