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