Chris Angelico <ros...@gmail.com> writes:
> for instance, I might have a socket object, and I might not, so I can
> use "if not self.socket: self.connect()" ...

This sounds like you want a Maybe or Option object.

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.  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()
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to