6

I want to receive some information from a user in a next way:

My score is of 10 - is already printed

Between 'is' and 'of' there is an empty place for user's input so he doesn't enter his information at the end( if using simple input() ) but in the middle. While user is entering some information it appears between 'is' and 'of'

Is there any possible way to do it?

0

2 Answers 2

3

One way to get something close to what you want is if you terminal supports ANSI escape codes:

x = input("My score is \x1b[s  of 10\x1b[u")

\x1b is the escape character. Neither escape character is dipsplayed on the screen; instead, they introduce byte sequences that the terminal interprets as an instruction of some kind. ESC[s tells the terminal to remember where the cursor is at the moment. ESC[u tells the terminal to move the cursor to the last-remembered position.

enter image description here

(The rectangle is the cursor in an unfocused window.)

Using a library that abstracts away the exact terminal you are using is preferable, but this gives you an idea of how such libraries interact with your terminal: it's all just bytes written to standard output.

Sign up to request clarification or add additional context in comments.

Comments

2

If you use console then consider importing curses library. It works on both linux and windows. Download it for windows from http://www.lfd.uci.edu/~gohlke/pythonlibs/#curses

With this library you have a total control over console. Here is the answer to your question. How to input a word in ncurses screen?

3 Comments

The other way would be far more complicated; I accomplished it a few years ago, I dont remember the code, but I used carriage return ( \r ) and constantly refreshed the console.
So far this is the only answer that appears to have come from someone who took the trouble to read the question.
@Usmiech See my answer for one possible example.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.