I'd like to print a string to command line / terminal in Windows and then edit / change the string and read it back. Anyone knows how to do it? Thanks
print "Hell" Hello! <---Edit it on the screen s = raw_input() print s Hello!
If it's for your own purposes, then here's a dirty wee hack using the clipboard without losing what was there before:
def edit_text_at_terminal(text_to_edit): import pyperclip # Save old clipboard contents so user doesn't lose them old_clipboard_contents = pyperclip.paste() #place text you want to edit in the clipboard pyperclip.copy(text_to_edit) # If you're on Windows, and ctrl+v works, you can do this: import win32com.client shell = win32com.client.Dispatch("WScript.Shell") shell.SendKeys("^v") # Otherwise you should tell the user to type ctrl+v msg = "Type ctrl+v (your old clipboard contents will be restored):n" # Get the new value, the old value will have been pasted new_value= str(raw_input(msg)) # restore the old clipboard contents before returning new value pyperclip.copy(old_clipboard_contents ) return new_value
Automating the keystrokes for other OSs will involve a different process.
Please remember this is a quick hack and not a "proper" solution. I will not be held responsible for loss of entire PhD dissertations momentarily stored on your clipboard.