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.
I prefer the already mentioned iterator-based solution to turn this into a for-loop. Another solution written directly is Knuth's "loop-and-a-half"
while 1:
len_name = data.read(4)
if not len_name:
break
names.append(data.read(len_name))
You can see by comparison how that's easily hoisted into its own generator and used as a for-loop.