Hi

I have a question about a problem I'm having with raw_input function in python.

I'm writing a CL program that requires a comment to be entered by the user, however problems arise when someone makes a mistake entering said comment.

comment = raw_input(Enter comment: )

User Input: Archie^?ve testing, where ^? is mean to be a backspace to get rid of a spelling mistake.

So is there a way to get input which allows for user error, so I don't get things like "Archiveve testing"

Recommended Answers

All 6 Replies

This could be due to your terminal property.
Try to set 'stty erase ^H' in your terminal.

Cheers cghtkh. I've tried this and no luck, I still get the same behaviour as before.

Your backspace character may be different depending on the keyboard mapping.
Try again using 'stty erase Ctrl-v<backspace>'
Note: Ctrl-v are 2 keys being pressed together, then release both keys and press "backspace".

commented: solved the issue +4

Hi

I have a question about a problem I'm having with raw_input function in python.

I'm writing a CL program that requires a comment to be entered by the user, however problems arise when someone makes a mistake entering said comment.

comment = raw_input(Enter comment: )

User Input: Archie^?ve testing, where ^? is mean to be a backspace to get rid of a spelling mistake.

So is there a way to get input which allows for user error, so I don't get things like "Archiveve testing"

If your OS is linux, you could try to add import readline which allows line editing, to your program. In windows, there are replacements for the readline module but I didn't test them (http://ipython.scipy.org/moin/PyReadline/Intro for example . Otherwise, google is your friend)

Or use something like easyGUI or Tkinter.

import easygui

""" test of multi-enter box
"""

def multeasygui_date() :
   title = "Date"
   msg = "Enter Date"
   fieldNames = ["mm","dd","ccyy"]
   fieldValues = []  # we start with blanks for the values
   fieldValues = easygui.multenterbox(msg,title, fieldNames, fieldValues )

   #----------------------------------------------------------------
   # from here down is basically the same for all easyGUI programs
   #----------------------------------------------------------------
   # data has been entered and button clicked
   # make sure that none of the fields was left blank
   while 1:
         if type(fieldValues) == None:
            fieldValues = [ -1, -1, -1 ]
	    break
         errmsg = ""
         for x in range(len(fieldNames)):
            if fieldValues[x].strip() == "":
               errmsg = errmsg + ('"%s" is a required field.\n\n' % fieldNames[x])
         if errmsg == "": 
            break # no problems found
         fieldValues = easygui.multenterbox(errmsg, title, fieldNames, fieldValues)
   return fieldValues[0], fieldValues[1], fieldValues[2]

##===================================================================
if "__main__" == __name__ :
   mm, dd, ccyy = multeasygui_date()
   print mm, dd, ccyy

cghtkh: Thank you very much! That has got it going!

Gribouillis: Cheers I'll have a look into that.

woooee: Sorry but I'm not looking for gui solution for a command line tool, but thank you anyway.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.