I am getting used to classes in python and I was trying to use them to make a project smarter. It concerns rivers morphodynamics.
I have 3 main inputs:
- geometry
- hydrograph
- grain size distribution
Here is how I organized my project:
- config.ini file where I define the 3 main inputs
- reader.py where I read the config.ini (with the configparser library)
- hydraulics.py file where I perform hydraulics calculations
- bedload.py file where I compute the bedload
- main.py file where the other files are called
Inside the bedload.py file I have a single class called "formula" which contains several methods, i.e. several bedload formulas.
class formula:
def __init__(...):
....
def formula1(...):
....
def formula2(...):
....
....
def formulan(...):
....
Each formula gives to arrays as output.
As an input I get the formula the user wants to use, and I choose it inside the main.py file as follows
import bedload
if formula == 'formula1':
bl = bedload.formula(...)
bl.formula1(...)
Is there a way to pass the input name to the class and choose the formula inside the class? Or maybe even a way to do what I am trying to do in a more pythonic way?
EDIT: to my understanding, the question suggested as similar to mine is indeed similar to mine, but the answers there are not exactly what I was looking for, which is what thebjorn suggested.