Hi
Thank you all for the helpful comments. For me, the key question is as
follows. There are two ways of asking for clamping, clipping or trimming
(call it what you will). They are:
aaa(lo, hi, num)
bbb(lo, hi)(num)
The question is then, which to provide? This is, in part, a syntactic
question. There's precedent in the standard library for providing both!
>>> str.join(',', 'abcde')
'a,b,c,d,e'
>>> ','.join('abcde')
'a,b,c,d,e'
>>> import struct
>>> struct.pack('II', 34, 55)
b'"\x00\x00\x007\x00\x00\x00'
>>> from struct import Struct
>>> Struct('II').pack(34, 55)
b'"\x00\x00\x007\x00\x00\x00'
>>> import re
>>> re.split('[a|b]+', 'AaababaBaaaCbabbD')
['A', 'B', 'C', 'D']
>>> from re import compile
>>> compile('[a|b]+').split('AaababaBaaaCbabbD')
['A', 'B', 'C', 'D']
It's worth noting that for the re module "compiled version of the most
recent patterns ... are cached", and that struct has a _clearcache function
(which clears the internal cache).
Others have noted that the bbb form can be obtained from the aaa form by
using functools.partial. Similarly, the aaa form can be obtained from the
aaa form, by a small piece of code. These observations by themselves don't
I think help us decide whether to provide one, the other, both or neither.
They simply show an equivalence of semantic power.
One of the key questions, as someone else has noted, is how often is there
need for using the same (lo, hi) pair with different values of num.
I think that's enough for now.
--
Jonathan
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/3HUO4ACGJILF64NNMBOGN5FVIHI54SGQ/
Code of Conduct: http://python.org/psf/codeofconduct/