refactoring - Python: avoiding pylint warnings about too many arguments -
I want to refact a large python function smaller. For example, consider the following code snippet:
x = x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9
def mysum (x1, x2, x3, x4, x5 , X6, x7, x8, x9): x = x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 return x The problem is that pylint triggers a warning About many arguments, I can avoid warning by doing something like this:
def mysum (d): x1 = d ['x1'] x2 = d ['x2']. X9 = d ['X 9'] x = x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 return x df mybigfunction (): ... d = {} d ['x1'] = X1 ... d ['X 9'] = x 9 x = mysum (d)But this view is ugly for me, it is necessary to write a lot of code which is also unnecessary.
Is there a better way to do this?
First, one of these:
"If you have 10 There is a process with parameters, then you probably miss something. "
Some 10 arguments are possibly related
Make an example, because there is not enough information in answer to the question directly:
class PersonInfo (object): Def __init __ (self, name, age, iq): self Name = name self.age = age self.iq = iq then its 10 argument function:
def f (x1, x2, name, x3 , Iq, x4, age, x5, x6, x7): ... is created:
def f (personinfo, x1, x2 , X3, x4, x5, x6, x7): ... and change in caller:
personinfo = PersonInfo (name, age, iq ) Results = f (person info, x1, x2, x3, x4, x5, x6, x7)
Comments
Post a Comment