Feature Wish: "%" Extension

Tim Peters tim.one at home.com
Sat Nov 3 00:42:45 EST 2001


[anonymous]
> ...
> For number->string conversion (see it coming yet?), the handy overloaded
> "%" operator handles radices 8, 10, and 16 -- with padding,
> zero-filling, prefixing (e.g. "0x").

Historically, this is simply because "%" is a C sprintf clone, and bases 8,
10 and 16 are handled by C by 2 isn't.  Greg Wilson submitted a patch to add
base 2:

<http://sf.net/tracker/index.php?func=detail&aid=455076&group_id=5470&atid=3
05470>

Unfortunately, it's got no review yet and 2.2 feature freeze is in effect.

> ...
> PS: I'm still dumbfounded why Python's division operator must behave
> differently than that in php, js, java, perl, awk, and C/C++ -- colleges
> do not teach BASIC anymore -- as I worry about all of my hardware
> interface code and auto-comment-wrapping editor :-)

Of the languges you mention, "integer" division in AWK, JavaScript and Perl
returns a floating-point result.  PHP does integer or float division, after
first checking to see whether the remainder is 0.  Java, C and C++ truncate
to an integer (although it's ill-defined in C89 when mixing signs).  Since
the languages you hold up as models actually have nothing in common here,
it's a bit of a challenge to guess what the heck you think "the obviously
correct way" may be.

rest-assured-python-will-act-like-one-of-them<wink>-ly y'rs  - tim





More information about the Python-list mailing list