Kudu
Kudu

Reputation: 6888

How to query an input in Python without outputting a new line (cont.)

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

Upvotes: 1

Views: 1228

Answers (3)

Don O'Donnell
Don O'Donnell

Reputation: 4728

>>> 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.

Upvotes: 0

vanza
vanza

Reputation: 9903

You can use the code in 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).

Upvotes: 0

Jordan Lewis
Jordan Lewis

Reputation: 17928

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.

Upvotes: 1

Related Questions