python - How to comprehend instructions like json.load(fp[, encoding[, cls[, obje...... ? -


i came across when reading python official documentation json.load:

json.load(fp[, encoding[, cls[, object_hook[, parse_float[, parse_int[, parse_constant[, object_pairs_hook[, **kw]]]]]]]]) 

may know how should comprehend this?

for example, if want set parameter parse_float 3, how should construct argument?

also, [, ....] mean? why there comma preceding formal parameters?

the square brackets […] common metalanguage notation used denote optional component of syntax in documentation , manuals. "optional" here means can either omit or keep inside brackets (but not subset of it). in sense analogous (…)? in regular expressions.

the usage predates python: can find in various unix manpages. not part of python's syntax, though find in many docs.

when documentation says:

foo(x[, y]) 

formally, means both of following acceptable:

foo(x) foo(x,  y) 

for example:

json.load(fp[, encoding[, cls[, object_hook[, parse_float[, parse_int[, parse_constant[, object_pairs_hook[, **kw]]]]]]]]) 

formally, means of following acceptable:

json.load(fp) json.load(fp, encoding) json.load(fp, encoding, cls) json.load(fp, encoding, cls, object_hook) json.load(fp, encoding, cls, object_hook, parse_float) json.load(fp, encoding, cls, object_hook, parse_float, parse_int) json.load(fp, encoding, cls, object_hook, parse_float, parse_int, parse_constant) json.load(fp, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook) json.load(fp, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw) 

however, documentation not precise notation: it's fine use keyword arguments skip of parameters don't care because of way arguments in python work, e.g.:

json.load(fp, parse_float=3) 

in fact, if @ same documentation python 3 see chose use clearer notation:

json.loads(s, encoding=none, cls=none, object_hook=none, parse_float=none, parse_int=none, parse_constant=none, object_pairs_hook=none, **kw)


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -