方括号“[]"在函数/类文档中是什么意思? [英] What do square brackets, "[]", mean in function/class documentation?

查看:52
本文介绍了方括号“[]"在函数/类文档中是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法弄清楚 csv.dictreader 的参数,并意识到我不知道方括号表示什么.

I am having trouble figuring out the arguments to csv.dictreader and realized I have no clue what the square brackets signify.

来自文档:

class csv.DictReader(csvfile[, fieldnames=None[, restkey=None[, restval=None[, dialect='excel'[, *args, **kwds]]]]])

我希望能对类实例化​​的参数进行总结.

I'd appreciate a summary of the arguments to the class instantiation.

谢谢

推荐答案

方括号表示这些参数是可选的.您可以将它们排除在外.

The square brackets indicate that these arguments are optional. You can leave them out.

因此,在这种情况下,您只需要求csvfile 参数传递给 csv.DictReader.如果您要传递第二个参数,它将被解释为 fieldnames 参数.第三个是 restkey

So, in this case you are only required to pass the csvfile argument to csv.DictReader. If you would pass a second parameter, it would be interpreted as the fieldnames arguments. The third would be restkey, etc.

如果您只想指定例如cvsfiledialect,那么你必须明确命名关键字参数,如下所示:

If you only want to specify e.g. cvsfile and dialect, then you'll have to name the keyword argument explicitly, like so:

csv.DictReader(file('test.csv'), dialect='excel_tab')

有关关键字参数的更多信息,请参阅第 4.7.2 节python.org 上的教程.

For more on keyword arguments, see section 4.7.2 of the tutorial at python.org.

这篇关于方括号“[]"在函数/类文档中是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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