what *is* a class?
holger krekel
pyth at devel.trillke.net
Mon Jun 17 11:37:31 EDT 2002
Jeff Epler wrote:
> This is not the Pythonic style. Even when it would sometimes be
> convenient, methods do not tend to return "self". That's why these
> don't work:
>
> # Iterate the sorted list
> for item in l.sort(): ...
>
> # Create and pack a widget
> x = Label(text="Wibble").pack()
>
> # Dump two objects to a pickle
> p = pickle.Pickler()
> p.dump(obj1).dump(obj2)
>
> One motivation for this is that if list.sort returns None, nobody
> will write
> for item in l.sort():
> thinking that a copy of l is sorted. It'll immediately blow up.
I agree that this is a good thing. But it wouldn't hurt to have
reverse, sort, extend
as standalone functions somewhere in the stdlib. They would return
a copy, so that you can write:
# iterate over a sorted copy of a list
for item in sort(l):
...
reverse could probabally be made an iterator so that it gets really
cheap to write:
for item in reverse(l):
...
And i think these functions should work with tuples and strings also.
cheers,
holger
More information about the Python-list
mailing list