
Ask HN: Large number of function arguments in Python - gcells
Hi all,<p>So I am working on a python application that can take its input as cli args and as a JSON string. The number and type of arguments is the same for both.<p>I have a function, lets call it _main that is coordinating with other modules that needs all these parameters as input. Currently I am passing ~15 arguments to _main. It looks nasty, and I believe there are better ways to accomplish this.<p>One way could be to create a request class having @property defined for all these parameters. I can create an object by using parameters from CLI or JSON as required and pass this object to _main.<p>The downside is that _main is called only at one place. Is it worth the effort to create a class that will be used only once? Or I am better off creating a dict and passing as <i></i>kwargs this function.<p>Most but not all of these parameters are needed by other modules that are called by _main. So, the request object created cannot be passed as is to other modules.<p>What are the best practices around this - to pass large number of arguments to functions?<p>thanks for taking the time to read this!
======
anoncake
Check out dataclasses[1]. It's in the standard library of Python 3.7 and
there's a backport for earlier versions.

[https://docs.python.org/3/library/dataclasses.html](https://docs.python.org/3/library/dataclasses.html)

~~~
gcells
Thanks, will look into it!

