views:

52

answers:

3

I already posted this, but here is the exact code:

x1 = input("")
x2 = input("-")
x3 = input("-")
x4 = input("-")

So, how would I do it so that there are no spaces between the first input and the next "-"?

Example:

1234-5678-9101-1121

A: 

Ugly, but you could use terminal escape sequences to delete the newline created by the user ending input between each successive call of input().

The appropriate sequences of escapes would be <Esc>[2K to erase the current line, and then possibly <Esc>[nC to move forwards n characters where n is calculated by retrieving the length of the string that the last input() call returned.

Jordan Lewis
A: 
>>> x1, x2, x3, x4 = raw_input("Input number as xxxx-xxxx-xxxx-xxxx").split('-')

If you're using Python version 3.x, replace rawinput with input.

Don O'Donnell
A: 

You can use the code in http://stackoverflow.com/questions/510357/python-read-a-single-character-from-the-user to read stdin character by character (basically reading it in unbuffered mode so that the user doesn't have to type enter before you can see the input).

vanza