python syntax question

TecHNooB

Diamond Member
Sep 10, 2005
7,458
1
76
csv.writer(csvfile[, dialect='excel'][, fmtparam])

I see blah[, blah blah] a lot. what does that mean?
 

Ken g6

Programming Moderator, Elite Member
Moderator
Dec 11, 1999
16,835
4,815
75
Python methods can take a variable number of arguments, and some arguments can be assigned to by name, I believe.
 

tfinch2

Lifer
Feb 3, 2004
22,114
1
0
Both posters pretty much have it.

[] signify optional. You do not use [] in your code, at least for this anyway. You can call csv.field_size_limit([new_limit]) in your code like so:

csv.field_size_limit()
csv.field_size_limit(someLimit)

A method writer can also set an argument to have a default value. That way if the caller does not specify that arg, the default value will be used.

You can also specify the name in the method call.

http://diveintopython.org/power_of_introspection/optional_arguments.html
 

jvroig

Platinum Member
Nov 4, 2009
2,394
1
81
Optional parameters. whose default values are specified further along the function/method entry.

I believe I first saw them used in Perl docs. Or was it PHP Manual? I forget. The use of square brackets to signify optional parameters have mostly become "invisible"/"transparent" to me, so I wouldn't be able to list down all language documentations following the same standard without having to browse through all of them.

However, not all languages support the "assigning by name" for optional function arguments as python, even though the documentation style is similar.