Closed mejroslav closed 1 year ago
Maybe you can simplify the attribute setting using **kwargs
argument? I think something like this should work:
class MyClass:
def __init__(self, **kwargs):
for key, value in kwargs.items():
setattr(self, key, value)
# Example usage
my_instance = MyClass(temperature=25, density=1.2, pressure=100)
Maybe you can create a new function?
Yes, a function for the saving will surely help readibility. Will do!
Maybe you can simplify the attribute setting using
**kwargs
argument? I think something like this should work:class MyClass: def __init__(self, **kwargs): for key, value in kwargs.items(): setattr(self, key, value) # Example usage my_instance = MyClass(temperature=25, density=1.2, pressure=100)
I'm not super sure about this one, becuase it is necessary that all the variables are given to the constructor. I'd still have to check for all of the keys having values, but I guess it would shorten the code a bit...
https://github.com/Quacken8/MagneticDisconnectSimulator/blob/faef3bd8e65fb5808206e7455553f4014a215acd/dataStructure.py#L164-L174
Maybe you can create a new function?