I am creating a simple package called pyma
, available on pypi.
I offer a way to calculate an exponential moving average over N day with a function called NDayEMA(n, data)
. (in fact, it's a class called NDayEMA
, with a function called compute()
but it is irrelevant here.)
I am trying to create a dynamically named function at run-time as shortcut for users.
For example:
NDayEMA(30, data)
and
EMA30(data)
would be the same and
EMA23(data)
EMA1023(data)
EMA12(data)
would also be available.
I understand I will need some reg-ex and processing, which is not required in your answer; I will get it myself! I am searching for how to receive the name of a function provide by the user and create a function with that name without raising error messages.
Here is a PHP equivalent from the Laravel PHP framework.
$user = DB::table('users')->where_email_and_password('example@gmail.com', 'secret');