How to read user input until EOF?

后端 未结 4 1483
有刺的猬
有刺的猬 2020-12-13 12:22

My current code reads user input until line-break. But I am trying to change that to a format, where the user can write input until strg+d to end his input.

I curren

4条回答
  •  旧时难觅i
    2020-12-13 13:09

    You could also do the following:

    acc = []
    out = ''
    while True:
        try:
            acc.append(raw_input('> ')) # Or whatever prompt you prefer to use.
        except EOFError:
            out = '\n'.join(acc)
            break
    

提交回复
热议问题