stylistic question -- optional return value

Bjorn Pettersen BPettersen at
Wed Aug 28 20:42:57 CEST 2002

> From: Andrew Koenig [mailto:ark at] 
> Suppose I have a function that sometimes returns one value 
> and sometimes returns two.  What's the cleanest way to define 
> such an interface?

The only time I've had type errors in my Python programs is when I've
tried to do this with a function. If I *have* to do it, I would probably
chose something along the lines of:

  def fn(args):
      class Tmp: pass
      tmp = Tmp()
      tmp.x = __
      tmp.y = __
      return tmp

your next question should be "why isn't fn a method of Tmp instead" to
which I would reply "indeed" <wink>

-- bjorn

More information about the Python-list mailing list