Input read more than one string line

Asked

Viewed 815 times

2

I’m having a problem, my code needs to read a string that contains more than one line, however it reads the first and to, as if when the line is skipped, it interprets as a "enter".

def depositlist():
deplist = str(input('''Entre com a lista de depósitos: '''))
clear = re.findall(':.+[.)$]', deplist)
print(clear)

I need him to read the list below and separate the lines referring to the values, excluding the blank line and the time.

1) #9ea587 - EXEMPLO DOS SANTOS - 4000,00 BRL - Neon


[4:46] 
2) #1abcd45 - FULANO DA SILVA- 1000,00 BRL - Santander

1 answer

3

You could create a function to perform the reading of multiple lines whereas the processing will be stopped when there is more than a certain number N line breaking.

Example (for N > 1):

def get_input():
    input('''Entre com a lista de depósitos: ''')
    lines = []
    count_line_break = 0
    while True:
        line = input()
        if not line:
            count_line_break = count_line_break + 1
        if count_line_break <= 1:
            lines.append(line)
        else:
            break
    text = '\n'.join(lines)
    return(str(text))

And your call would be like this:

deplist = get_input()

Adapted from https://stackoverflow.com/questions/30239092/how-to-get-multiline-input-from-user

Browser other questions tagged

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