T
Tim Lesher
I'm using the marshal library to unmarshal a file containing one or
more objects. The canonical way seems to be:
objs = []
while 1:
try:
objs.append(marshal.load(fobj))
except EOFError:
break
Maybe it's just me, but it seems as if this should be iterable. I can
get the behavior I want by writing:
def itermarshal(fobj):
while 1:
try:
yield marshal.load(fobj)
except EOFError:
raise StopIteration
objs = [obj for obj in itermarshal(fobj)]
But it seems that this should be built-in somewhere. Given that the
marshal library has been around since roughly forever, is it just that
no one's bothered to add iteration support to it, or am I missing
something?
Thanks.
more objects. The canonical way seems to be:
objs = []
while 1:
try:
objs.append(marshal.load(fobj))
except EOFError:
break
Maybe it's just me, but it seems as if this should be iterable. I can
get the behavior I want by writing:
def itermarshal(fobj):
while 1:
try:
yield marshal.load(fobj)
except EOFError:
raise StopIteration
objs = [obj for obj in itermarshal(fobj)]
But it seems that this should be built-in somewhere. Given that the
marshal library has been around since roughly forever, is it just that
no one's bothered to add iteration support to it, or am I missing
something?
Thanks.