Hi, On Sat, Sep 20, 2014 at 2:34 PM, Noufal Ibrahim KV <nou...@nibrahim.net.in> wrote: > > The problem now is that this function sometimes returns a single thing > and some times a list. I don't like this since I have to alter my > calling code to handle this. >
I generally try to make the return type consistent. I will do something like if consolidated: return [object] else: return the_list_of_objects What I also do is, the object will have a consolidated flag as well. The the code that invokes this will have to do: stats = get_stats(consolidated = True) ... ... for stat in stats: if stat.consolidated: do something. else: do something else I run into this problem frequently because, there is a tool(framework) that I write at office that is used by multiple teams. So, to keep stuff consistent, I always return the same type and let the user handle the result the way he/she wants. Thanks -- Thank you Balachandran Sivakumar _______________________________________________ BangPypers mailing list BangPypers@python.org https://mail.python.org/mailman/listinfo/bangpypers