I have a class A
and its constructor takes many variables. In my project, these variables are identified from another python file, B
.
file B
looks like this:
p1 = 4
p2 = 1
...
pN = 'dd'
#and a bunch of other variables.
Class A
looks like this:
class A():
def __init__(p1,p2,...,pN):
The number of parameters included in the constructor of A
is very high, and I don't think it would be easy for a user (i.e., another one who wants to use my class) to initiate. However, I want my class to be generic and decoupled from other files in the project (i.e., file B
). My question is how class A
should be constructed?
A solution in my mind would be to pass the name of the python file that defines the parameters to a constructer in A
:
class A():
def __init__(self,python_filename):
self.p1 = python_filename.p1
self.p2 = python_filename.p2
def __init__(self,p1,p2,...,pN):
My first thought is to make a class in B
that has static members, would that be a good design in terms of being pythonic and object-oriented?
Aucun commentaire:
Enregistrer un commentaire