1

I would like to get user input while printing to the screen. I researched this a lot. but didn't find anything. I'm not very advanced with class programming in Python, so I didn't understand the other examples on stackoverflow.

Example:

import time

def user_input():
    while True:
        raw_input("say smth: ")

def output():
    while True:
        time.sleep(3)
        print "hi"

input()
output()

I want the prompt to stay, even if the output is printing "hi". I already tried an example, but the input prompt disappears even if it is in a while loop.

1 Answer 1

1

First, let's go over your code

import time

def user_input():
    while True:
        raw_input("say smth: ")

def output():
    while True:
        time.sleep(3)
        print "hi"

input()
output()

You are calling input() which is not actually your function name. It's user_input(). Also, once user_input() is called, output() will never be called because the while True condition in user_input() is always True, meaning it never exits outside the function.

Also, if you want to do something with multithreading, but you don't understand classes in Python, you should probably do a tutorial related to classes.

Take a look at this other StackOverflow Post on a multithreaded program.

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

Comments

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.