473,513 Members | 2,559 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Iterating over marshal

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.

--
Tim Lesher
tl*****@gmail.com

Oct 6 '06 #1
2 1268
Tim Lesher wrote:
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
the canonical way to do this is to put the objects in a sequence
container *before* marshalling them.

</F>

Oct 6 '06 #2
On Oct 6, 4:19 pm, Fredrik Lundh <fred...@pythonware.comwrote:
Tim Lesher wrote:
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:
breakthe canonical way to do this is to put the objects in a sequence
container *before* marshalling them.
That makes sense; unfortunately, I'm unmarshalling from an external
data source I don't control (the Perforce version control client).

--
Tim Lesher
tl*****@gmail.com

Oct 6 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
2149
by: Just Me | last post by:
The following almost works. The problem is Marshal.PtrToStringAuto seems to terminate at the first null so I don't get the full string. Any suggestions on how to fix this? Or how to improve the...
2
1892
by: Pierre Rouleau | last post by:
Hi all, When using Python 2.4.x on a Win32 box, marshal.loads(marshal.dumps(1e66666)) returns 1.0 instead of infinity as it should and does under Python 2.5 (also running on Win32 ). This...
2
7180
by: O.B. | last post by:
When using Marshal to copy data from a byte array to the structure below, only the first byte of the "other" array is getting copied from the original byte array. What do I need to specify to get...
0
2101
by: Charming12 | last post by:
Hi All, I have a strange problem and due to my inefficiency with IntPtr i am unable to figure it out. I have an structure something like: public struct Detail { public int age; public...
0
7260
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7537
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7099
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7525
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5685
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5086
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4746
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1594
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
799
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.