Skip to content

Commit f0f96a9

Browse files
AA-Turnerhugovk
andauthored
GH-108202: Document calendar's command-line interface (#109020)
Co-authored-by: Hugo van Kemenade <[email protected]>
1 parent 6971e40 commit f0f96a9

File tree

2 files changed

+144
-1
lines changed

2 files changed

+144
-1
lines changed

Doc/library/calendar.rst

+143
Original file line numberDiff line numberDiff line change
@@ -489,3 +489,146 @@ The :mod:`calendar` module defines the following exceptions:
489489

490490
Module :mod:`time`
491491
Low-level time related functions.
492+
493+
494+
.. _calendar-cli:
495+
496+
Command-Line Usage
497+
------------------
498+
499+
.. versionadded:: 2.5
500+
501+
The :mod:`calendar` module can be executed as a script from the command line
502+
to interactively print a calendar.
503+
504+
.. code-block:: shell
505+
506+
python -m calendar [-h] [-L LOCALE] [-e ENCODING] [-t {text,html}]
507+
[-w WIDTH] [-l LINES] [-s SPACING] [-m MONTHS] [-c CSS]
508+
[year] [month]
509+
510+
511+
For example, to print a calendar for the year 2000:
512+
513+
.. code-block:: console
514+
515+
$ python -m calendar 2000
516+
2000
517+
518+
January February March
519+
Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
520+
1 2 1 2 3 4 5 6 1 2 3 4 5
521+
3 4 5 6 7 8 9 7 8 9 10 11 12 13 6 7 8 9 10 11 12
522+
10 11 12 13 14 15 16 14 15 16 17 18 19 20 13 14 15 16 17 18 19
523+
17 18 19 20 21 22 23 21 22 23 24 25 26 27 20 21 22 23 24 25 26
524+
24 25 26 27 28 29 30 28 29 27 28 29 30 31
525+
31
526+
527+
April May June
528+
Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
529+
1 2 1 2 3 4 5 6 7 1 2 3 4
530+
3 4 5 6 7 8 9 8 9 10 11 12 13 14 5 6 7 8 9 10 11
531+
10 11 12 13 14 15 16 15 16 17 18 19 20 21 12 13 14 15 16 17 18
532+
17 18 19 20 21 22 23 22 23 24 25 26 27 28 19 20 21 22 23 24 25
533+
24 25 26 27 28 29 30 29 30 31 26 27 28 29 30
534+
535+
July August September
536+
Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
537+
1 2 1 2 3 4 5 6 1 2 3
538+
3 4 5 6 7 8 9 7 8 9 10 11 12 13 4 5 6 7 8 9 10
539+
10 11 12 13 14 15 16 14 15 16 17 18 19 20 11 12 13 14 15 16 17
540+
17 18 19 20 21 22 23 21 22 23 24 25 26 27 18 19 20 21 22 23 24
541+
24 25 26 27 28 29 30 28 29 30 31 25 26 27 28 29 30
542+
31
543+
544+
October November December
545+
Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
546+
1 1 2 3 4 5 1 2 3
547+
2 3 4 5 6 7 8 6 7 8 9 10 11 12 4 5 6 7 8 9 10
548+
9 10 11 12 13 14 15 13 14 15 16 17 18 19 11 12 13 14 15 16 17
549+
16 17 18 19 20 21 22 20 21 22 23 24 25 26 18 19 20 21 22 23 24
550+
23 24 25 26 27 28 29 27 28 29 30 25 26 27 28 29 30 31
551+
30 31
552+
553+
554+
The following options are accepted:
555+
556+
.. program:: calendar
557+
558+
559+
.. option:: --help, -h
560+
561+
Show the help message and exit.
562+
563+
564+
.. option:: --locale LOCALE, -L LOCALE
565+
566+
The locale to use for month and weekday names.
567+
Defaults to English.
568+
569+
570+
.. option:: --encoding ENCODING, -e ENCODING
571+
572+
The encoding to use for output.
573+
:option:`--encoding` is required if :option:`--locale` is set.
574+
575+
576+
.. option:: --type {text,html}, -t {text,html}
577+
578+
Print the calendar to the terminal as text,
579+
or as an HTML document.
580+
581+
582+
.. option:: year
583+
584+
The year to print the calendar for.
585+
Must be a number between 1 and 9999.
586+
Defaults to the current year.
587+
588+
589+
.. option:: month
590+
591+
The month of the specified :option:`year` to print the calendar for.
592+
Must be a number between 1 and 12,
593+
and may only be used in text mode.
594+
Defaults to printing a calendar for the full year.
595+
596+
597+
*Text-mode options:*
598+
599+
.. option:: --width WIDTH, -w WIDTH
600+
601+
The width of the date column in terminal columns.
602+
The date is printed centred in the column.
603+
Any value lower than 2 is ignored.
604+
Defaults to 2.
605+
606+
607+
.. option:: --lines LINES, -l LINES
608+
609+
The number of lines for each week in terminal rows.
610+
The date is printed top-aligned.
611+
Any value lower than 1 is ignored.
612+
Defaults to 1.
613+
614+
615+
.. option:: --spacing SPACING, -s SPACING
616+
617+
The space between months in columns.
618+
Any value lower than 2 is ignored.
619+
Defaults to 6.
620+
621+
622+
.. option:: --months MONTHS, -m MONTHS
623+
624+
The number of months printed per row.
625+
Defaults to 3.
626+
627+
628+
*HTML-mode options:*
629+
630+
.. option:: --css CSS, -c CSS
631+
632+
The path of a CSS stylesheet to use for the calendar.
633+
This must either be relative to the generated HTML,
634+
or an absolute HTTP or ``file:///`` URL.

Lib/calendar.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ def main(args=None):
721721
parser.add_argument(
722722
"-L", "--locale",
723723
default=None,
724-
help="locale to be used from month and weekday names"
724+
help="locale to use for month and weekday names"
725725
)
726726
parser.add_argument(
727727
"-e", "--encoding",

0 commit comments

Comments
 (0)