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.

ekhumoro
  • 115,249
  • 20
  • 229
  • 336
Blood
  • 13
  • 1
  • 8

1 Answers1

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.

Community
  • 1
  • 1
freddiev4
  • 2,501
  • 2
  • 26
  • 46