> For instance, it is quite common to use integers as keys.  If you are  
> inserting keys in order, it is about a hundred times faster to encode  
> the ints in big-endian byte order than than little-endian:
> 
> class MyIntDB(object):
>       def __setitem__(self, key, item):
>                self.db.put(struct.pack('>Q', key), serializer(item))
>          def __getitem__(self, key):
>                return unserializer(self.db.get(struct.pack('>Q', key)))

I guess Guido wants you to write

class MyIntDB(object):
  def __setitem__(self, key, item):
    self.db.put(struct.pack('>Q', key).encode("latin-1"),
                serializer(item))
  def __getitem__(self, key):
    return unserializer(self.db.get(
       struct.pack('>Q', key).encode("latin-1"))

here.

> How do you envision these types of tasks being accomplished with  
> unicode keys?  It is conceivable that one could write a custom  
> unicode encoding that accomplishes this, convert the key to unicode,  
> and pass the custom encoding name to the constructor.

See above. It's always trivial to do that with latin-1 as the encoding
(I'm glad you didn't see that, either :-).

Regards,
Martin
_______________________________________________
Python-3000 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe: 
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com

Reply via email to