在任何python API文档中,为什么可以使用嵌套样式编写参数? [英] In any python API documentation, why are optional arguments written in a nested style?

查看:230
本文介绍了在任何python API文档中,为什么可以使用嵌套样式编写参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是为什么这样做:

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]]]]]]]]]]]]]]]]]])

哪个看起来很丑陋,令人困惑,但是出现在我遇到过的每一个api文档中,我可能会缺少一些基本的python

Which seems ugly and confusing, yet appears in every api docs I've ever come across, I may lack some basic python knowledge.

推荐答案

我没有任何真实的来源来回覆我的声明

以嵌套样式呈现的可选位置参数将强制字段的正确排序。

Optional positional arguments presented in a nested style would enforce the proper ordering of the fields.

例如 os fdopen 的模块

os.fdopen(fd[, mode[, bufsize]])

表示模式和bufsize是可选的,但如果您指定了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

进行初始化。例如,在[ re]模块,用于拆分

For example in [re] module for split

split(string, maxsplit=0)

这篇关于在任何python API文档中,为什么可以使用嵌套样式编写参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆