Dear Noufal, Have not gone through all the replies...so may be i am repeating...may be I am not in my senses :))
I would create a "stats_bundle" object, with members like stats_val and stats_list, which are initialized to None. So you always get a stats_bundle object which you can pass around to the handler function in the calling code. Since one of the above members is always going to be None, a simple check in the handler will be fine..i guess. But all this is stylistic...so it depends. Take care, Vishal Thanks and best regards, Vishal Sapre --- Please DONT print this email, unless you really need to. Save Energy & Paper. Save the Earth. On Sat, Sep 20, 2014 at 9:57 PM, Sriram Karra <karra....@gmail.com> wrote: > On Sat, Sep 20, 2014 at 5:15 PM, Noufal Ibrahim KV <nou...@nibrahim.net.in > > > wrote: > > > > > > From the thread so far, Anand's solution is the one I like > > best. Although it's something tailored for my problem rather than a > > general pattern. > > > > > Anand's solution is good. But with the added context you have given - why > are you not creating classes for CPU and Machine, with get_stats() and > set_stats() methods for them? Something like: > > class CPU: > def set_stats (self, cpu_t): > self.cpu_stats = cpu_t > > def get_stats (self): > return self.cpu_stats > > class Machine: > def __init__ (self, n_cpus): > self.cpus = [CPU() for i in range(0, n_cpus)] > > def fetch_stats (self): > stats_list = psutils.get_cpu_stats() > for i, stat in enumerate(stats_list): > cpu[i].set_stats(stat) > > self.cpu_stats_summary = psutils.get_cpu_stats(summary=True) > > def get_cpu_stats_summary (self): > return self.cpu_stats_summary > _______________________________________________ > BangPypers mailing list > BangPypers@python.org > https://mail.python.org/mailman/listinfo/bangpypers > _______________________________________________ BangPypers mailing list BangPypers@python.org https://mail.python.org/mailman/listinfo/bangpypers