John Machin wrote: > def unpack(bytes, unpack_entry=unpack_entry): > '''Return dictionary gotten by unpacking supplied bytes. > Both keys and values in the returned dictionary are byte-strings. > ''' > bytedict = {} > ptr = 0 > while 1: > key, val, ptr = unpack_entry(bytes, ptr) > bytedict[key] = val > if ptr == len(bytes): > break > # That's beautiful code -- as pretty as a cane-toad.
Well, it's nearly right. It has a transposition error. > # Well-behaved too, a very elegant response to unpack(pack({})) Yes, you're right. An attempt to read bytes that aren't there. > # Try this: > blen = len(bytes) > while ptr < blen: > key, val, ptr = unpack_entry(bytes, ptr) > bytedict[key] = val > > return bytedict I've committed such a change. Thank you. -- Jonathan -- http://mail.python.org/mailman/listinfo/python-list