Mixing files and loops

后端 未结 4 661
Happy的楠姐
Happy的楠姐 2020-11-29 05:52

I\'m writing a script that logs errors from another program and restarts the program where it left off when it encounters an error. For whatever reasons, the developers of t

4条回答
  •  难免孤独
    2020-11-29 06:20

    You get the ValueError because your code probably has for line in original: in addition to original.readline(). An easy solution which fixes the problem without making your program slower or consume more memory is changing

    for line in original:
        ...
    

    to

    while True:
        line = original.readline()
        if not line: break
        ...
    

提交回复
热议问题