stylistic question -- optional return value

François Pinard pinard at
Wed Aug 28 20:28:04 CEST 2002

[Andrew Koenig]

> Suppose I have a function that sometimes returns one value and sometimes
> returns two.  What's the cleanest way to define such an interface?

> Yet another possibility is to return (False, x) or (True, x, y).

Or maybe (1, x) or (2, (x, y)) ?  You always unpack a 2-tuple from the
function result, and decide what to do from there.

> What is the most Pythonic way of solving this problem?

Undoubtedly, the way which is most legible! :-)

François Pinard

More information about the Python-list mailing list