ACCEPTED: PEP 285

Erik Max Francis max at alcyone.com
Thu Apr 4 00:53:43 EST 2002


"Kris J. Zaragoza" wrote:

> Maybe, but I'm not sure this is strictly necessary, since according to
> the PEP:
> 
>     ("%s" % str(True)) => "True"

Unless the alternate choice is accepted where str(True) == '1'.

> It's not as pretty as having a format specifier for it, but I'd
> imagine it will do for the short term.  Then, of course, you have to
> wonder what exactly
> 
>     ("%d" % True) => ?
> 
> should print.  After all, bools are ints too.  Should this be "1" or
> an error of some sort?

Since, as you say, bools are ints, it only makes sense that "%d" % True
== '1', since int(True) == 1.

> And what if you've done some arithmetic on a
> bool and end up with another value?  What would your proposed %b
> format specifier print for
> 
>    val = int.__new__(bool,42)
>    ("%b" % val) => ?
> 
> I really should stop thinking about these things and just go to
> bed... :-)

Just like %s does an implicit call to str, %b should do an implicit call
to bool.  So this should be just the same as "%b" % bool(val).

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE
/  \ Nationalism is an infantile sickness.
\__/ Albert Einstein
    Alcyone Systems' Daily Planet / http://www.alcyone.com/planet.html
 A new, virtual planet, every day.



More information about the Python-list mailing list