python needs leaning stuff from other language

Steven D'Aprano steve at
Sat Apr 4 03:25:30 CEST 2009

On Fri, 03 Apr 2009 22:42:33 +0100, Tim Wintle wrote:

> On Fri, 2009-04-03 at 13:12 -0400, Mel wrote:
>> >>> I think it would also be better to have One (and prefereably Only
>> >>> One) Obvious Way To Do It. That obvious way, for those who work
>> >>> with Python's ‘set’ and ‘dict’, is a ‘clear’ method. It seems best
>> >>> to have ‘list’ conform with this also.
>> >> 
>> >> Does that mean a one-off special case rule to forbid slices having a
>> >> default?
>> > 
>> > Why would it do that?
>> Well, if list.clear were truly and strictly to be the only way to clear
>> the contents of a list, then assigning nothing via the default slice
>> would have to be ruled out.  `somelist[:] = []` is just a special case
>> of assignment to a slice generally.
> agreed. If .clear was to be added then really assignments to slices
> should be entirely removed.

That's total nonsense. Where do people get this ridiculous urban legend 
that there is "only one way to do it" in Python?

The Zen says:

"There should be one-- and preferably only one --obvious way to do it."

does not mean "only one way to do it". It is a *prescription* that there 
SHOULD be one OBVIOUS way to do a task, not a prohibition on more than 
one way to do a task.

Such a prohibition would be stupid *and* impossible to enforce:

# Four ways to remove trailing spaces from a string. There are others.

s.rstrip(" ")  # the one obvious way

while s.endswith(" "):
    s = s[:-1]

while True:
    if s[-1] == ' ':
        s = s[0:-1]

L = []
trailing_spaces = True
for c in reversed(s):
    if c == ' ' and trailing_spaces:
    trailing_spaces = False
s = ''.join(L)


More information about the Python-list mailing list