[Python-ideas] Why operators are useful

Steven D'Aprano steve at pearwood.info
Mon Mar 18 19:08:46 EDT 2019


On Mon, Mar 18, 2019 at 03:12:52PM +0100, Antoine Pitrou wrote:

> (also, don't forget you can still use the copy() + update() method)

If we had fluent method calls, we could write:

    process(mapping.copy().update(other))

but we don't, so we use a pointless temporary variable:

    temp = mapping.copy()
    temp.update(other)
    process(temp)
    del temp  # don't pollute the global namespace


turning what ought to be a simple expression into an extra two or three 
statements.


-- 
Steven


More information about the Python-ideas mailing list