Proper use versus using * args in Python

I was looking at the source code for the open source package that I am using. Almost every function uses * args instead of the named arguments. It is difficult for me to follow and use the code, because every time I want to call a function, I need to go back, select the source code and determine what arguments should be and in what order they should be. I have a question: is there a good reason to use * args in every function or is it an abuse of the concept? Thanks, -b

+5
source share
5 answers

This may be a personal argument, but I only use * args and ** kwargs when I have many optional fields, where some fields are used only in a specific context.

The only other case I used for the arguments was when I created the XML RPC client for the cloud API. Since I just passed the parameters to the base layer, and since the function was dynamically generated, I had no choice but to use the * args arguments, because I could not know all the parameters in advance.

In most cases, you don’t even need to. I think this is mostly laziness than anything else.

Some people from Java and C # can use this as a replacement for "params", but there are so many ways to pass optional parameters to python.

, * args, .

+4

*args - , ( ). , *args, *args.

+3
+3

*args, . , . , (x, y, z) , (*args).

, , (, (x, y, z) (2, 3), , ), , .

*args.

, (C ) , *args. , , . , - - , , .

, , , .

+2

(, , ), (*args, **kwargs).

(*args, **kwargs) , (__init__ ). , , (, , ).

**kwargs, , .

, *args ( - , , ), , *args , " ". *websites *spaceships *watermelons, *args. *args. *args "x, y a z, x a z", , . ( None , , None) and be transmitted by keyword, not by position.

+2
source

All Articles