1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Run a loop while waiting for a user input

Discussão em 'Python' iniciado por Stack, Novembro 26, 2025.

  1. Stack

    Stack Membro Participativo

    I want to run a loop in my script while the user has not input anything. But when they have input something I want the loop to break.

    The issue I am currently having is that when using the input() function, the script will stop and wait for an input, but I want to run another part of the script while waiting for the user input.

    I have tried using try: with a raw_input():

    while True:
    try:
    print('SCAN BARCODE')
    userInput= raw_input()
    #doing something with input
    except:
    #run this while there is no input


    With this, I find that whatever is in the except: will always run, but it will not run try: even when there is a user input. If I change raw_input() to input() the script just waits at input() and doesn't run anything in the except:.

    How do I achieve what I am after?

    Continue reading...

Compartilhe esta Página