stylistic question -- optional return value
dougfort
dougfort at dougfort.net
Wed Aug 28 17:58:27 EDT 2002
On Wed, 28 August 2002, Andrew Koenig wrote:
>
> Suppose I have a function that sometimes returns one value and sometimes
> returns two. What's the cleanest way to define such an interface?
>
> For the sake of this discussion, I'll use x to refer to the value that
> is always returned and y to refer to the optional value.
How about this:
class Result:
pass
def the_function:
result = Result();
result.x = 42
if some-condition:
result.y = "aha!"
return result
Doug Fort <dougfort at dougfort.net>
http://www.dougfort.net
More information about the Python-list
mailing list