PEP0238 lament
Steve Horne
sh at ttsoftware.co.uk
Tue Jul 24 08:35:13 EDT 2001
On Tue, 24 Jul 2001 08:56:53 +0000 (UTC), Duncan Booth
<duncan at NOSPAMrcp.co.uk> wrote:
>Stephen Horne <steve at lurking.demon.co.uk> wrote in
>news:gmhplt4kitb3514p6kkdfg1kgl1eqr1fqg at 4ax.com:
>
>> If you had as many cases of "£"+str(Amount/100)+"."+str(amount%100)
>> and similar in your code as I do
>
>This is an example where even today you might be better off writing
>"£%d.%02d" % divmod(Amount, 100)
>especially if you ever have single digit pennies.
The code examples were simplified to get to the point, but this is
true - barring a few points...
1. A lot of people these scripts are passed on to are non-programmers
who, nonetheless, need to do some fiddling to keep things up to
date.
Separate / and % with formatting done longhand (and with the
number of digits required specified, of course) tend to cause less
confusion.
2. I just plain habitually use / and % anyway, having a C and C++
background and having never (previously) had a reason to change.
3. I dislike % substitution because I dislike sprintf formatting, and
besides - I tend to think it should specify the subscript for the
data to substitute in the string - not just rely on the list/tuple
order.
Not a particularly *good* reason in point 3, but theres a little bit
of irrationality in most people.
--
Steve Horne
Home : steve at lurking.demon.co.uk
Work : sh at ttsoftware.co.uk
More information about the Python-list
mailing list