[Tutor] Problem with logic while extracting data from binary file

Bryan Fodness bryan.fodness at gmail.com
Fri Mar 28 21:24:10 CET 2008

```Thanks again,

Still lost, even with watching the variables.  I see that it kicks out of
the loop, but don't understand what I have done to cause this.  I'm sorry
for repeated emails, but I have spent multiple days on this.  I have added
another while loop that I think should work, but I can't seem to keep it in
the while loop.  I feel like I am getting close.

It seems like it gets everything at the first level , but not the way I
expected.  It seems to get the first value inside the first while loop, and
then goes outside the loop to get the next three.  I would have expected it
to return the values as it goes through the first while loop (since they are
at the same level), then when it sees the nested identifier, go into the
second while loop and return values.

Any insight would be wonderful.

def parseSequence(data, start):
group_num = data[start:start+2]
element_num = data[start+2:start+4]
vl_field = data[start+4:start+8]
length = struct.unpack('hh', vl_field)
value = data[start+8:(start+8+length)]
pos = start+8+length
element = (group_num+element_num)
if element == '\xfe\xff\x00\xe0':
data = value
while start < 536: #length:  # 536
group_num = data[start:start+2]
element_num = data[start+2:start+4]
vl_field = data[start+4:start+8]
length = struct.unpack('hh', vl_field)
value = data[start+8:(start+8+length)]
start = start+8+length
element = (group_num+element_num)
if element == '\xfe\xff\x00\xe0':
data = value
while start < 112: #length:  # 112, 112, 116, 116
group_num = data[start:start+2]
element_num = data[start+2:start+4]
vl_field = data[start+4:start+8]
length = struct.unpack('hh', vl_field)
value = data[start+8:(start+8+length)]
start = start+8+length
element = (group_num+element_num)
return element, start, value
else:
return element, start, value
else:
return  element, pos, value
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20080328/e298e103/attachment.htm
```