Paul Rubin <no.email@nospam.invalid>: > Marko's suggestion > > rv = f() > if rv is not None: > return rv > rv = g() > if rv is not None: > return rv > return h() > > seems unspeakably ugly.
Well, "unspeakably" is exaggeration IMO. It is a bit lengthy but it is crystal clear. While the "or" pattern is neat, I wouldn't make too much of it. > Rather than None on failure maybe f() and g() could return an empty > list on failure, or a one-element list containing the item on success. > That uses lists to simulate a Maybe type. > > Then the above could go (Python 3, untested): > > def tries(): > yield from f() > yield from g() > yield [h()] > return tries().next() I think the medicine in this case is worse than the disease. Marko -- https://mail.python.org/mailman/listinfo/python-list