2

My question is about this crawler.

Looking at the code's help:

def help(arg0: str):
    print(
        "DESCRIPTION: crawler script for StackExchange"
        "\n\n"
        "SYNOPSIS:\n"
        f"{arg0} "
        f"[--site {' | '.join([k for k in SE_SITE_ROOT.keys()])} ] "
        "[-b | --begin-page <page>] "
        "[-e | --end-page <page>] "
        "[-c | --crawler <crawler-number>/<total-crawlers>] "
        "[--total-pages] "
        "[--no-overwrite] "
        "[--patrol] "
        "[--save-preview] "
        "[--hook-script <script name>] "
        "[-p | --post <post id>] "
        "\n"
    )
    sys.exit(1)

Why are "crawler-number" and "total-crawlers" between angle brackets in "[-c | --crawler <crawler-number>/<total-crawlers>] "? What is the function of the forward slash?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
R. S.
  • 115
  • 5
  • Look at the usage: https://github.com/approach0/a0-crawlers/blob/13ab5e29727c1ed94a7bbf7598a2fdb83206b4ea/crawler-stackexchange.py#L382-L388. It's expecting two numbers, e.g. `1/4`. – jonrsharpe Mar 15 '22 at 16:45
  • Does this answer your question? [What is the meaning of angle brackets in Python?](https://stackoverflow.com/questions/43118694/what-is-the-meaning-of-angle-brackets-in-python) – shamnad sherief Mar 15 '22 at 16:45
  • @shamnadsherief While that question also misidentifies the code, it is about something completely different. – MisterMiyagi Mar 15 '22 at 16:49
  • This is help text for the program. The angle brackets are just shorthand hints for optional parameters. They don't have any meaning in python and are not used when calling the program itself. Its just a way to give terse hints for calls. Suppose I see help for `foo [--bar=]`. It would suggest that `foo` has an optinal parameter `bar` and could be called as `foo --bar=myvalue`. – tdelaney Mar 15 '22 at 16:49
  • @shamnadsherief: no. The comment above yours and the answer below are better. – R. S. Mar 15 '22 at 16:50
  • @shamnadsherief, your link has nothing to do with this particular question. – shrewmouse Mar 15 '22 at 16:51

1 Answers1

4

This is not about python at all. These are standard notations in documentation of unix commands.

  • The square brackets [ ] mean "this is optional". So, either you specify -c | --crawler <something>, or you don't specify a -c option at all.

  • The pipe | means "or". Either you specify -c <something>, or --crawler <something>. It is common for options to have a "full name" with two dashes followed by a word, and a "short name" with one dash followed by a letter. The two names are synonymous.

  • The forward slash / literally means /. You're expected to write an actual slash.

  • The angle brackets < > mean "replace this with an actual value". So, you shouldn't write -c crawler-number/total-crawlers, but rather -c 12/24 or -c 7/8 or -c 1/157 or something similar.

Stef
  • 13,242
  • 2
  • 17
  • 28