0

I have function that are implemented inside a class as shown below

Methods.py

class Perform_stats:

    def get_mean(self,data):
        m = np.mean(data)
        return m 

    def get_rms(self,data):
        r = np.sqrt(np.mean(data**2))
        return r
       ....

Testmethods.py

import Methods as mds

ps = mds.Perform_stats()

df_mean = ps.get_mean(df)

df_rms  = ps.get_rms(df)

So in Testmethods.py I need to pass the same data df to the different function of Perform_stats class, is it possible to pass the name of the functions that are to be implemented as a list so that I can call all the functions and get the result as dict?

Something like as shown below

import Methods as mds

ps = mds.Perform_stats(df,methods=['mean','rms','All']) #All is the default arugument which return a dictionary

I found post which does the same, but I failed to implement my requirement.

Learner
  • 118
  • 10
  • What is the result you are willing to have and what are you getting at the current state? – dstrants Feb 04 '20 at 18:46
  • @dstrants Currently I am getting different data frames like df_rms, df_mean. What I need is a dictionary `ps` which stores values returned by the respective functions called in the list which is passed as a parameter. – Learner Feb 04 '20 at 18:50
  • Is the `Perform_stats` class just an example? (It should probably be named `PerformStats`, by the way) I think I sort of understand what you're asking, and it seems somewhat unusual, can you provide some more context for this? – AMC Feb 04 '20 at 22:24
  • @AMC Yes `Perform_stats` is just an example, I need to have one API exposed where I give the `list` of functions to be executed as a parameter to in the API. If I give `All` it executes all the functions, else it I mention only a few list of functions like `['mean', 'rms',....]` only those functions will be executed. This should return the results of the executed function combined as a `dictionary` – Learner Feb 05 '20 at 03:20

0 Answers0