• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

python syntax question

TecHNooB

Diamond Member
csv.writer(csvfile[, dialect='excel'][, fmtparam])

I see blah[, blah blah] a lot. what does that mean?
 
Python methods can take a variable number of arguments, and some arguments can be assigned to by name, I believe.
 
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
 
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.
 
Back
Top