Answer the question
In order to leave comments, you need to log in
How to print text before input() in Python?
In Python, is it possible to ask for user input with input() in the console, while simultaneously printing the text on the line BEFORE the prompt? It should look something like this:
Text 1
Text 2
Text 3
Please enter something: abc
Whenever new text is printed, it must be printed after the previous text and before the input() prompt. Also, do not interrupt user input.
So after printing "Text 4" the console should look like this:
Text 1
Text 2
Text 3
Text 4
Please enter something: abc
Is it possible to do this in Python without using any external libraries?
I already tried using \r, \b and similar codes as well as streams. I also know that I will probably need one thread to print text and I have another one asking for user input.
Answer the question
In order to leave comments, you need to log in
#-*- coding: utf-8 -*-
from threading import Thread
from time import sleep
def counter():
i = 0
while(True):
sleep(0.8)
i += 1
print(i)
def cmd():
while(True):
print(f'\x1b[FCommand: {input()}')
Thread(target = counter).start()
Thread(target = cmd).start()
But
you just don't like it? Or is it necessary to remove the invitation phrase from the screen without fail?
x = input("Please enter something:")
while True:
print(text)
x = input('enter some...:')
text = text + x
clr
import os
text='text1'
for i in range(5):
print(text)
newtext=input('Enter something')
text+='\n'+newtext
os.system('clear') #либо cls для винды
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question