it doesn't work ;) [class recursive function]

Ethan Furman ethan at
Thu Sep 16 01:23:20 CEST 2010

I need some fresh eyes, or better brains, or both!

The expected debugging output is a list of names in alphabetical order 
from each node (there are about 90 of them);  what I am getting is this:

--> dbf.tables.Index.from_file('', r'aad13658_last_name_for_state.idx')

starting next_item call for root
<open file 'aad13658_last_name_for_state.idx', mode 'rb' at 0x013BD458> 
512 30
more nodes
CARNAHAN                       1536
ENGLUND                        1024
HOLSTEIN                       2048
MATTHEWS                       2560
ROSENFELD                      3072
TERWILLIGER                    3584
YAZZOLINO                      4096

and then it stops.  I should get about nine of these sections, and I'm 
only getting one.

<code snippet>

class Index(object):
     def from_file(cls, table, index_file):

         def get_idx_records(data, length, howmany):
             print "get_idx_records: keylen - %d;  howmany - %d" %\
                        (length, howmany)
             ptr = 0
             current = 0
             while current < howmany:
                 key = data[ptr:ptr+length].replace('\x00','')
                 rec = io.unpackLongInt(data[ptr+length:ptr+length+4],\
                 yield key, rec
                 ptr += length + 4
                 current += 1

         def next_item(idx_file, node_loc, keylen):
             print idx_file, node_loc, keylen, '\n','-----'
             data_chunk =
             attributes = io.unpackShortInt(data_chunk[:2])
             howmany = io.unpackShortInt(data_chunk[2:4])
             if attributes in (2, 3):
                 print "actual records"
                 for key, rec in get_idx_records(data_chunk[12:512],\
                         keylen, howmany):
                     yield key, rec
                 print "more nodes"
                 for ignore, next_node in \
                        keylen, howmany):
                     print ignore, next_node
                     next_item(idx_file, next_node, keylen)

         idx = object.__new__(cls)
         #- idx.key = lambda rec: DoNotIndex
         data = open(index_file, 'rb')
         header =
         rootnode = io.unpackLongInt(header[:4])
         keylen = io.unpackShortInt(header[12:14])
         idx.__doc__ = header[16:236].replace('\x00','')
         for_expr = header[236:456].replace('\x00','')
         if for_expr:
             idx.__doc__ += ' for ' + for_expr.replace('=','==')
         print "starting next_item call for root"
         for rec in next_item(data, rootnode, keylen):
             print rec

</code snippet>

Any ideas appreciated!

-------------- next part --------------
A non-text attachment was scrubbed...
Name: aad13658_last_name_for_state.idx
Type: application/octet-stream
Size: 4608 bytes
Desc: not available
URL: <>

More information about the Python-list mailing list