How to skip the line in python input?

Asked

Viewed 82 times

-3

Hello I’m making a code here to send emails, and I wanted that at the time of the inputs of the message when I hit the Enter it jumps the line and does not stop the input, that it only stops when the user presses the Enter twice

message = MIMEText(str(input("Mensagem: ")))
  • Remembering that "input" already returns a string, so it is not necessary to do str(input(...)) - the patter int( input(...) ) that is found in many pieces of code, including answers here, is no special syntax applicable to input - is simply called the "function" int with whatever the input return - and if this is a valid string for conversion, returns an integer number.

1 answer

1

By default, Python does not include very flexible tools for developing applications on the terminal: "Input" is pretty much the only option - for anyone on Unix (Linux or Mac OS), you can use the "curses" library to develop a complex app on the terminal (but it’s a lot more work than "input") .

The good news is that in general people ask how to catch an entrance without tighten <enter> - in that case, one has to use a lib the part as curses or terminedia - but to plus of a enter, just create a function that you control, using various inputs. Unfortunately you can’t navigate with arrows, if the user wants to edit a line up, for example - but you can write a very quiet multilayered message:


def multi_input(msg, help="(digite uma linha em branco para terminar)"):
    print(msg)
    print(help)
    resultado = []
    linha = None
    while linha != "":
        linha = input()
        resultado.append(linha)
    return "\n".join(resultado)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.