Gerhard Häring gh at
Fri Mar 14 00:50:57 CET 2003

Max Khesin wrote:
> Hi all,
> I just started with the snake, coming from a C++ background (and what a cool
> snake it is!).
> Anyway, is method nesting possible in python, e.g.
> PrintLines(os.popen('dir').readlines().sort())
> or
> PrintLines((os.popen('dir').readlines()).sort())
> even if sort() does not return a reference to self, are there methods that
> do and is it a common Python programming style?

No, list methods (like sort) don't return the original list. It's
common to use a temporary variable for this. If you want to, you can
subclass list so sort returns the changed list, if you *really* want
this behaviour.

Wether lists methods should return their changed value has been
discussed at length on this list in the past, so you should be able to
use to review this discussion and the rationale for
the current behaviour.

mail:   gh at

More information about the Python-list mailing list