How to loop until EOF in Python?

后端 未结 6 478
南笙
南笙 2020-12-08 03:38

I need to loop until I hit the end of a file-like object, but I\'m not finding an \"obvious way to do it\", which makes me suspect I\'m overlooking something, well, obvious.

6条回答
  •  天命终不由人
    2020-12-08 04:09

    I'd go with Tendayi's suggestion re function and iterator for readability:

    def read4():
        len_name = data.read(4)
        if len_name:
            len_name = struct.unpack("

提交回复
热议问题