[ACCEPTED]-What do square brackets, "[]", mean in function/class documentation?-python

Accepted answer
Score: 28

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

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

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

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

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

Score: 2

Usually in api documentation square brackets 2 mean optional. I would think they mean the 1 same here.

Score: 2

This is actually a subset of the widely 3 used notation to unambiguously describe 2 language syntax called Backus-Naur Form (see Wikipedia article 1 for details).

Score: 1

To reiterate what the others have said, the 8 arguments are optional.

If you leave out 7 optional parts, the remaining fieldnames=, restval=, restkey= or dialect= keywords 6 tell the function which parts are missing.

The 5 syntax doesn't suggest it, but I wouldn't 4 be surprised if the keywords allow the arguments 3 to be specificied in any order, except that 2 the last two arguments must be either both 1 specified, or both omitted.

More Related questions