On 08/02/2012 17:41, Gregory, Matthew wrote:
Alan Gauld wrote:
Since a class is effectively a disguised dictionary I'm not sure why you
want to do this? If you just want to access the method by name then why
not just call getattr(spam,'get_mean')?
Thanks for the feedback and, yes, this makes s
Alan Gauld wrote:
> Since a class is effectively a disguised dictionary I'm not sure why you
> want to do this? If you just want to access the method by name then why
> not just call getattr(spam,'get_mean')?
Thanks for the feedback and, yes, this makes sense. My use case was when the
statistic
On 07/02/12 19:32, Gregory, Matthew wrote:
class Statistics(object):
STAT = {
'MEAN': get_mean,
'SUM': get_sum,
}
...
if __name__ == '__main__':
spam = Statistics(4, 3)
print spam.get_stat('mean')
print spam.get_stat('sum')
Since a class is effect
On Tue, Feb 7, 2012 at 2:32 PM, Gregory, Matthew
wrote:
> Hi list,
>
> I'm trying to understand how to use a class-level dictionary to act as a
> switch for class methods. In the contrived example below, I have the
> statistic name as the key and the class method as the value.
>
> class Statist
Hi list,
I'm trying to understand how to use a class-level dictionary to act as a switch
for class methods. In the contrived example below, I have the statistic name
as the key and the class method as the value.
class Statistics(object):
STAT = {
'MEAN': get_mean,
'SUM': ge