stylistic question -- optional return value
François Pinard
pinard at iro.umontreal.ca
Wed Aug 28 14:28:04 EDT 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 http://www.iro.umontreal.ca/~pinard
More information about the Python-list
mailing list