Short answer: solution 1 will have fields named paramN
, solution 2 will have arguments to the constructor, but not the fields in the class instance.
The easy way to do this is to demonstrate it. I'm going to change the names of your classes so they don't conflict, and I'm going to limit each to two params for brevity.
class SomeClass1():
param1 = 'param1'
param2 = 'param2'
def some_method(self):
return self.param1
class SomeClass2():
def __init__(self, param1 = 'param1', param2 = 'param2'):
pass
def some_method(self):
return self.param1
# prints the string 'param1'
one = SomeClass1()
print(one.some_method())
# throws a NameError,
# because SomeClass2 instances don't have the field
two = SomeClass2()
print(two.some_method())
If you want SomeClass2 to have the param fields, you'll need to handle that in the __init()__
method by capturing the arguments:
class SomeClass2():
def __init__(self, param1 = 'param1', param2 = 'param2'):
self.param1 = param1
self.param2 = param2
Be warned though, those arguments are not hard coded as you requested.
# Prints the integer 1, not the string 'param1'
two = SomeClass2(param1 = 1, param2 = 2)
print(two.some_method())
As to which is correct, well, that depends on what you're trying to do. Both solutions are valid python code.