[Python-ideas] Combining test and assignment (original) (raw)

Terry Reedy tjreedy at udel.edu
Mon Jan 23 00:46:14 CET 2012


On 1/22/2012 7:04 AM, Paul Moore wrote:

On 22 January 2012 04:51, Steven D'Aprano<steve at pearwood.info> wrote:

Assignment as an expression feels unnatural to me:

if spam() as x != 'ham': frobulate(x) doesn't really correspond to any natural English order.

The best I can come up with is "if x, which is the result of calling 'spam', is not equal to 'ham', then frobulate x". But I am not going to call that 'natural' speech. More normal would be "Get the result of spam(). If it it not 'ham', then frobulate it." As others noted, the pronoun 'it' is a substitute for local names. But doing that for more than one object or value gets awkward. "Get ham() and spam(). If the first is less than the second, multiply the first by the second plus 3." "Former' and 'latter' are another pair of standardized pronoun-like names. The math device of temporary names is really handy.

-- Terry Jan Reedy



More information about the Python-ideas mailing list