问题
It's just, why do this:
find([spec=None[, fields=None[, skip=0[, limit=0[, timeout=True[, snapshot=False[, tailable=False[, sort=None[, max_scan=None[, as_class=None[, slave_okay=False[, await_data=False[, partial=False[, manipulate=True[, read_preference=ReadPreference.PRIMARY[, exhaust=False[, compile_re=True[, **kwargs]]]]]]]]]]]]]]]]]])
Which seems ugly and confusing, yet appears in every api docs I've ever come across, I may lack some basic python knowledge.
回答1:
I do not have any authentic source to back my statement
Optional positional arguments presented in a nested style would enforce the proper ordering of the fields.
For Example in os module for fdopen
os.fdopen(fd[, mode[, bufsize]])
Indicates that mode and bufsize are optional but if you are specifying bufsize you should also specify mode.
For Keywords argument, on the other hand, a default value is specified without any order enforcement to inndicate that the value is optional in which case, the parameter would be initialized with the default value
For example in [re] module for split
split(string, maxsplit=0)
回答2:
This is a convention borrowed from extended Backus-Naur form. As pointed out above by Abhijit, the nesting means optional to the optional argument etc.
来源:https://stackoverflow.com/questions/24950651/in-any-python-api-documentation-why-are-optional-arguments-written-in-a-nested