Near Final PEP 247 - API for Cryptographic Hash Functions

Robert Amesz reqhye72zux at mailexpire.com
Sat Sep 22 20:49:56 EDT 2001


Donn Cave wrote:

> Quoth Robert Amesz <reqhye72zux at mailexpire.com>:
>
>| Since the raw digest can (and probably will) contain both control 
>| characters (< 32) and high-ASCII (> 126) it can't be said te be
>| 'nicely printable'. 
> 
> That doc is one thing, and common practice is another.  I would go
> so far as to say, the doc is wrong.
> 
> There are a bunch of different objectives for "self to string"
> methods, and only two standard methods.  In the standard library,
> when I last looked I found a lot of cases where __str__ is the
> object's data as a string, for use in a computation that requires a
> string.

Assuming that the doc describes Guido's intentions for str(), and thus 
predates most of the standard library it might be fairer to assume some 
of its programmers got it wrong. <about half a wink here>

If 'abusing' str() is common practice, should the docs be altered to 
suit that practice? I'm not sure. But don't forget that str() is used 
implicitly by print and % (for "%s" formats) to convert non-string 
types to strings, so condoning letting __str__ return strings with 
nonprintable characters would be at odds with that, and therefore a 
Very Bad Idea.


Robert Amesz



More information about the Python-list mailing list