A small inconsistency in syntax?

Terry Reedy tjreedy at home.com
Thu Oct 25 20:56:35 EDT 2001


"Michael Abbott" <michael.g.abbott at ntlworld.com> wrote in message
news:Xns9145D94516673michaelrcpcouk at 62.253.162.104...
> However, Python tuple assignment does look somewhat like pattern
matching;
> for example, sometimes my .read() method returns some (one) thing,
and I
> write:
>
>     time, status, ((value, boring),) = myobject.read()
>
> So here I think of this as matching the one value (itself a pair of
values)
> that happens to be returned.  This looks awfully like pattern
matching (cf
> Haskell).

An so it is.  If the patterns do not match, an exception is raised.
However, after the match, the names (in your example above) 'time',
'status', 'value', and 'boring' are then bound to the corresponding
objects in the current namespace.

Terry J. Reedy






More information about the Python-list mailing list