@@ -448,3 +448,146 @@ The :mod:`calendar` module defines the following exceptions:
448
448
449
449
Module :mod: `time `
450
450
Low-level time related functions.
451
+
452
+
453
+ .. _calendar-cli :
454
+
455
+ Command-Line Usage
456
+ ------------------
457
+
458
+ .. versionadded :: 2.5
459
+
460
+ The :mod: `calendar ` module can be executed as a script from the command line
461
+ to interactively print a calendar.
462
+
463
+ .. code-block :: shell
464
+
465
+ python -m calendar [-h] [-L LOCALE] [-e ENCODING] [-t {text,html}]
466
+ [-w WIDTH] [-l LINES] [-s SPACING] [-m MONTHS] [-c CSS]
467
+ [year] [month]
468
+
469
+
470
+ For example, to print a calendar for the year 2000:
471
+
472
+ .. code-block :: console
473
+
474
+ $ python -m calendar 2000
475
+ 2000
476
+
477
+ January February March
478
+ Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
479
+ 1 2 1 2 3 4 5 6 1 2 3 4 5
480
+ 3 4 5 6 7 8 9 7 8 9 10 11 12 13 6 7 8 9 10 11 12
481
+ 10 11 12 13 14 15 16 14 15 16 17 18 19 20 13 14 15 16 17 18 19
482
+ 17 18 19 20 21 22 23 21 22 23 24 25 26 27 20 21 22 23 24 25 26
483
+ 24 25 26 27 28 29 30 28 29 27 28 29 30 31
484
+ 31
485
+
486
+ April May June
487
+ Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
488
+ 1 2 1 2 3 4 5 6 7 1 2 3 4
489
+ 3 4 5 6 7 8 9 8 9 10 11 12 13 14 5 6 7 8 9 10 11
490
+ 10 11 12 13 14 15 16 15 16 17 18 19 20 21 12 13 14 15 16 17 18
491
+ 17 18 19 20 21 22 23 22 23 24 25 26 27 28 19 20 21 22 23 24 25
492
+ 24 25 26 27 28 29 30 29 30 31 26 27 28 29 30
493
+
494
+ July August September
495
+ Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
496
+ 1 2 1 2 3 4 5 6 1 2 3
497
+ 3 4 5 6 7 8 9 7 8 9 10 11 12 13 4 5 6 7 8 9 10
498
+ 10 11 12 13 14 15 16 14 15 16 17 18 19 20 11 12 13 14 15 16 17
499
+ 17 18 19 20 21 22 23 21 22 23 24 25 26 27 18 19 20 21 22 23 24
500
+ 24 25 26 27 28 29 30 28 29 30 31 25 26 27 28 29 30
501
+ 31
502
+
503
+ October November December
504
+ Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
505
+ 1 1 2 3 4 5 1 2 3
506
+ 2 3 4 5 6 7 8 6 7 8 9 10 11 12 4 5 6 7 8 9 10
507
+ 9 10 11 12 13 14 15 13 14 15 16 17 18 19 11 12 13 14 15 16 17
508
+ 16 17 18 19 20 21 22 20 21 22 23 24 25 26 18 19 20 21 22 23 24
509
+ 23 24 25 26 27 28 29 27 28 29 30 25 26 27 28 29 30 31
510
+ 30 31
511
+
512
+
513
+ The following options are accepted:
514
+
515
+ .. program :: calendar
516
+
517
+
518
+ .. option :: --help , -h
519
+
520
+ Show the help message and exit.
521
+
522
+
523
+ .. option :: --locale LOCALE , -L LOCALE
524
+
525
+ The locale to use for month and weekday names.
526
+ Defaults to English.
527
+
528
+
529
+ .. option :: --encoding ENCODING , -e ENCODING
530
+
531
+ The encoding to use for output.
532
+ :option: `--encoding ` is required if :option: `--locale ` is set.
533
+
534
+
535
+ .. option :: --type {text ,html} , -t {text ,html}
536
+
537
+ Print the calendar to the terminal as text,
538
+ or as an HTML document.
539
+
540
+
541
+ .. option :: year
542
+
543
+ The year to print the calendar for.
544
+ Must be a number between 1 and 9999.
545
+ Defaults to the current year.
546
+
547
+
548
+ .. option :: month
549
+
550
+ The month of the specified :option: `year ` to print the calendar for.
551
+ Must be a number between 1 and 12,
552
+ and may only be used in text mode.
553
+ Defaults to printing a calendar for the full year.
554
+
555
+
556
+ *Text-mode options: *
557
+
558
+ .. option :: --width WIDTH , -w WIDTH
559
+
560
+ The width of the date column in terminal columns.
561
+ The date is printed centred in the column.
562
+ Any value lower than 2 is ignored.
563
+ Defaults to 2.
564
+
565
+
566
+ .. option :: --lines LINES , -l LINES
567
+
568
+ The number of lines for each week in terminal rows.
569
+ The date is printed top-aligned.
570
+ Any value lower than 1 is ignored.
571
+ Defaults to 1.
572
+
573
+
574
+ .. option :: --spacing SPACING , -s SPACING
575
+
576
+ The space between months in columns.
577
+ Any value lower than 2 is ignored.
578
+ Defaults to 6.
579
+
580
+
581
+ .. option :: --months MONTHS , -m MONTHS
582
+
583
+ The number of months printed per row.
584
+ Defaults to 3.
585
+
586
+
587
+ *HTML-mode options: *
588
+
589
+ .. option :: --css CSS , -c CSS
590
+
591
+ The path of a CSS stylesheet to use for the calendar.
592
+ This must either be relative to the generated HTML,
593
+ or an absolute HTTP or ``file:/// `` URL.
0 commit comments