Understanding "help" command description syntax - explanation needed

Chris Angelico rosuav at gmail.com
Wed Nov 5 07:20:55 EST 2014


On Wed, Nov 5, 2014 at 11:13 PM, Ivan Evstegneev
<webmailgroups at gmail.com> wrote:
> That's what I'm talking about (asking actually), where do you know it from?
> I mean, if there are some resources, which explain all these syntax abbreviations? The general concept.
>
>
> Like this one(just for example):
> class bytearray([source[, encoding[, errors]]]) --- What does it mean?
> Is that  I can use it in optional way?
> Like: class bytearray(source) or class bytearray(encoding) ?
> or just write down all three of them?
> In which format do I do so?

With consecutive defaults, like that, it's written as a nested series.
You have three optional parts: the first is "source[, encoding[,
errors]]", the second (completely inside that) is ", encoding[,
errors]", and the third (also inside) is ", errors". The first one
gives you two options:

class bytearray()
class bytearray(source[, encoding[, errors]])

Then that gives you two more options:
class bytearray(source)
class bytearray(source, encoding[, errors])

Which itself gives two options:
class bytearray(source, encoding)
class bytearray(source, encoding, errors)

So what you actually have is four real, usable options:
class bytearray()
class bytearray(source)
class bytearray(source, encoding)
class bytearray(source, encoding, errors)

Does that make sense? You're allowed to provide no options, or
anywhere up to three, but they have to be the first N options.

In this particular case, it doesn't make sense to provide the later
options without also providing the earlier ones. The encoding and
errors parameters affect how source is interpreted, and errors affects
how the encoding copes with stuff it can't handle, so it wouldn't make
sense to provide either without source, or source and errors without
encoding. That's why it's written as a nested set of optional
sections, rather than as a series of stand-alone options.

ChrisA



More information about the Python-list mailing list