Greg Ewing <greg.ew...@canterbury.ac.nz> wrote: > Neil Schemenauer wrote: >> Objects that implement __str__ can also implement __bytes__ if they >> can guarantee that ASCII characters are always returned, > > I think __ascii_ would be a better name. I'd expect > a method called __bytes__ on an int to return some > version of its binary value.
I realize now we can't use __bytes__. Currently, passing an int to bytes() causes it to construct an object with that many null bytes. If we are going to support format() (I'm not convinced it is nessary and could easily be added in a later version), then we need an equivalent to __format__. My vote is either: def __formatascii__(self, spec): ... or def __ascii__(self, spec): ... Previously I was thinking of __bformat__ or __formatb__ but having ascii in the method name is a great reminder. Objects with a natural arbitrary byte representation can implement __bytes__ and %s should use that if it exists. Neil _______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com