gooderp18绿色标准版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1037 line
95KB

  1. <!DOCTYPE html>
  2. <html lang="en" data-content_root="../">
  3. <head>
  4. <meta charset="utf-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
  6. <meta property="og:title" content="calendar — General calendar-related functions" />
  7. <meta property="og:type" content="website" />
  8. <meta property="og:url" content="https://docs.python.org/3/library/calendar.html" />
  9. <meta property="og:site_name" content="Python documentation" />
  10. <meta property="og:description" content="Source code: Lib/calendar.py This module allows you to output calendars like the Unix cal program, and provides additional useful functions related to the calendar. By default, these calendars have..." />
  11. <meta property="og:image" content="https://docs.python.org/3/_static/og-image.png" />
  12. <meta property="og:image:alt" content="Python documentation" />
  13. <meta name="description" content="Source code: Lib/calendar.py This module allows you to output calendars like the Unix cal program, and provides additional useful functions related to the calendar. By default, these calendars have..." />
  14. <meta property="og:image:width" content="200" />
  15. <meta property="og:image:height" content="200" />
  16. <meta name="theme-color" content="#3776ab" />
  17. <title>calendar — General calendar-related functions &#8212; Python 3.12.3 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
  18. <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=80d5e7a1" />
  19. <link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=bb723527" />
  20. <link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=b20cc3f5" />
  21. <script src="../_static/documentation_options.js?v=2c828074"></script>
  22. <script src="../_static/doctools.js?v=888ff710"></script>
  23. <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
  24. <script src="../_static/sidebar.js"></script>
  25. <link rel="search" type="application/opensearchdescription+xml"
  26. title="Search within Python 3.12.3 documentation"
  27. href="../_static/opensearch.xml"/>
  28. <link rel="author" title="About these documents" href="../about.html" />
  29. <link rel="index" title="Index" href="../genindex.html" />
  30. <link rel="search" title="Search" href="../search.html" />
  31. <link rel="copyright" title="Copyright" href="../copyright.html" />
  32. <link rel="next" title="collections — Container datatypes" href="collections.html" />
  33. <link rel="prev" title="zoneinfo — IANA time zone support" href="zoneinfo.html" />
  34. <link rel="canonical" href="https://docs.python.org/3/library/calendar.html" />
  35. <style>
  36. @media only screen {
  37. table.full-width-table {
  38. width: 100%;
  39. }
  40. }
  41. </style>
  42. <link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">
  43. <link rel="shortcut icon" type="image/png" href="../_static/py.svg" />
  44. <script type="text/javascript" src="../_static/copybutton.js"></script>
  45. <script type="text/javascript" src="../_static/menu.js"></script>
  46. <script type="text/javascript" src="../_static/search-focus.js"></script>
  47. <script type="text/javascript" src="../_static/themetoggle.js"></script>
  48. </head>
  49. <body>
  50. <div class="mobile-nav">
  51. <input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"
  52. aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu" />
  53. <nav class="nav-content" role="navigation">
  54. <label for="menuToggler" class="toggler__label">
  55. <span></span>
  56. </label>
  57. <span class="nav-items-wrapper">
  58. <a href="https://www.python.org/" class="nav-logo">
  59. <img src="../_static/py.svg" alt="Python logo"/>
  60. </a>
  61. <span class="version_switcher_placeholder"></span>
  62. <form role="search" class="search" action="../search.html" method="get">
  63. <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">
  64. <path fill-rule="nonzero" fill="currentColor" d="M15.5 14h-.79l-.28-.27a6.5 6.5 0 001.48-5.34c-.47-2.78-2.79-5-5.59-5.34a6.505 6.505 0 00-7.27 7.27c.34 2.8 2.56 5.12 5.34 5.59a6.5 6.5 0 005.34-1.48l.27.28v.79l4.25 4.25c.41.41 1.08.41 1.49 0 .41-.41.41-1.08 0-1.49L15.5 14zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"></path>
  65. </svg>
  66. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" />
  67. <input type="submit" value="Go"/>
  68. </form>
  69. </span>
  70. </nav>
  71. <div class="menu-wrapper">
  72. <nav class="menu" role="navigation" aria-label="main navigation">
  73. <div class="language_switcher_placeholder"></div>
  74. <label class="theme-selector-label">
  75. Theme
  76. <select class="theme-selector" oninput="activateTheme(this.value)">
  77. <option value="auto" selected>Auto</option>
  78. <option value="light">Light</option>
  79. <option value="dark">Dark</option>
  80. </select>
  81. </label>
  82. <div>
  83. <h3><a href="../contents.html">Table of Contents</a></h3>
  84. <ul>
  85. <li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">calendar</span></code> — General calendar-related functions</a><ul>
  86. <li><a class="reference internal" href="#command-line-usage">Command-Line Usage</a></li>
  87. </ul>
  88. </li>
  89. </ul>
  90. </div>
  91. <div>
  92. <h4>Previous topic</h4>
  93. <p class="topless"><a href="zoneinfo.html"
  94. title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">zoneinfo</span></code> — IANA time zone support</a></p>
  95. </div>
  96. <div>
  97. <h4>Next topic</h4>
  98. <p class="topless"><a href="collections.html"
  99. title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">collections</span></code> — Container datatypes</a></p>
  100. </div>
  101. <div role="note" aria-label="source link">
  102. <h3>This Page</h3>
  103. <ul class="this-page-menu">
  104. <li><a href="../bugs.html">Report a Bug</a></li>
  105. <li>
  106. <a href="https://github.com/python/cpython/blob/main/Doc/library/calendar.rst"
  107. rel="nofollow">Show Source
  108. </a>
  109. </li>
  110. </ul>
  111. </div>
  112. </nav>
  113. </div>
  114. </div>
  115. <div class="related" role="navigation" aria-label="related navigation">
  116. <h3>Navigation</h3>
  117. <ul>
  118. <li class="right" style="margin-right: 10px">
  119. <a href="../genindex.html" title="General Index"
  120. accesskey="I">index</a></li>
  121. <li class="right" >
  122. <a href="../py-modindex.html" title="Python Module Index"
  123. >modules</a> |</li>
  124. <li class="right" >
  125. <a href="collections.html" title="collections — Container datatypes"
  126. accesskey="N">next</a> |</li>
  127. <li class="right" >
  128. <a href="zoneinfo.html" title="zoneinfo — IANA time zone support"
  129. accesskey="P">previous</a> |</li>
  130. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  131. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  132. <li class="switchers">
  133. <div class="language_switcher_placeholder"></div>
  134. <div class="version_switcher_placeholder"></div>
  135. </li>
  136. <li>
  137. </li>
  138. <li id="cpython-language-and-version">
  139. <a href="../index.html">3.12.3 Documentation</a> &#187;
  140. </li>
  141. <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
  142. <li class="nav-item nav-item-2"><a href="datatypes.html" accesskey="U">Data Types</a> &#187;</li>
  143. <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">calendar</span></code> — General calendar-related functions</a></li>
  144. <li class="right">
  145. <div class="inline-search" role="search">
  146. <form class="inline-search" action="../search.html" method="get">
  147. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  148. <input type="submit" value="Go" />
  149. </form>
  150. </div>
  151. |
  152. </li>
  153. <li class="right">
  154. <label class="theme-selector-label">
  155. Theme
  156. <select class="theme-selector" oninput="activateTheme(this.value)">
  157. <option value="auto" selected>Auto</option>
  158. <option value="light">Light</option>
  159. <option value="dark">Dark</option>
  160. </select>
  161. </label> |</li>
  162. </ul>
  163. </div>
  164. <div class="document">
  165. <div class="documentwrapper">
  166. <div class="bodywrapper">
  167. <div class="body" role="main">
  168. <section id="module-calendar">
  169. <span id="calendar-general-calendar-related-functions"></span><h1><a class="reference internal" href="#module-calendar" title="calendar: Functions for working with calendars, including some emulation of the Unix cal program."><code class="xref py py-mod docutils literal notranslate"><span class="pre">calendar</span></code></a> — General calendar-related functions<a class="headerlink" href="#module-calendar" title="Link to this heading">¶</a></h1>
  170. <p><strong>Source code:</strong> <a class="reference external" href="https://github.com/python/cpython/tree/3.12/Lib/calendar.py">Lib/calendar.py</a></p>
  171. <hr class="docutils" />
  172. <p>This module allows you to output calendars like the Unix <strong class="program">cal</strong> program,
  173. and provides additional useful functions related to the calendar. By default,
  174. these calendars have Monday as the first day of the week, and Sunday as the last
  175. (the European convention). Use <a class="reference internal" href="#calendar.setfirstweekday" title="calendar.setfirstweekday"><code class="xref py py-func docutils literal notranslate"><span class="pre">setfirstweekday()</span></code></a> to set the first day of
  176. the week to Sunday (6) or to any other weekday. Parameters that specify dates
  177. are given as integers. For related
  178. functionality, see also the <a class="reference internal" href="datetime.html#module-datetime" title="datetime: Basic date and time types."><code class="xref py py-mod docutils literal notranslate"><span class="pre">datetime</span></code></a> and <a class="reference internal" href="time.html#module-time" title="time: Time access and conversions."><code class="xref py py-mod docutils literal notranslate"><span class="pre">time</span></code></a> modules.</p>
  179. <p>The functions and classes defined in this module
  180. use an idealized calendar, the current Gregorian calendar extended indefinitely
  181. in both directions. This matches the definition of the “proleptic Gregorian”
  182. calendar in Dershowitz and Reingold’s book “Calendrical Calculations”, where
  183. it’s the base calendar for all computations. Zero and negative years are
  184. interpreted as prescribed by the ISO 8601 standard. Year 0 is 1 BC, year -1 is
  185. 2 BC, and so on.</p>
  186. <dl class="py class">
  187. <dt class="sig sig-object py" id="calendar.Calendar">
  188. <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">calendar.</span></span><span class="sig-name descname"><span class="pre">Calendar</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">firstweekday</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#calendar.Calendar" title="Link to this definition">¶</a></dt>
  189. <dd><p>Creates a <a class="reference internal" href="#calendar.Calendar" title="calendar.Calendar"><code class="xref py py-class docutils literal notranslate"><span class="pre">Calendar</span></code></a> object. <em>firstweekday</em> is an integer specifying the
  190. first day of the week. <a class="reference internal" href="#calendar.MONDAY" title="calendar.MONDAY"><code class="xref py py-const docutils literal notranslate"><span class="pre">MONDAY</span></code></a> is <code class="docutils literal notranslate"><span class="pre">0</span></code> (the default), <a class="reference internal" href="#calendar.SUNDAY" title="calendar.SUNDAY"><code class="xref py py-const docutils literal notranslate"><span class="pre">SUNDAY</span></code></a> is <code class="docutils literal notranslate"><span class="pre">6</span></code>.</p>
  191. <p>A <a class="reference internal" href="#calendar.Calendar" title="calendar.Calendar"><code class="xref py py-class docutils literal notranslate"><span class="pre">Calendar</span></code></a> object provides several methods that can be used for
  192. preparing the calendar data for formatting. This class doesn’t do any formatting
  193. itself. This is the job of subclasses.</p>
  194. <p><a class="reference internal" href="#calendar.Calendar" title="calendar.Calendar"><code class="xref py py-class docutils literal notranslate"><span class="pre">Calendar</span></code></a> instances have the following methods:</p>
  195. <dl class="py method">
  196. <dt class="sig sig-object py" id="calendar.Calendar.iterweekdays">
  197. <span class="sig-name descname"><span class="pre">iterweekdays</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#calendar.Calendar.iterweekdays" title="Link to this definition">¶</a></dt>
  198. <dd><p>Return an iterator for the week day numbers that will be used for one
  199. week. The first value from the iterator will be the same as the value of
  200. the <a class="reference internal" href="#calendar.firstweekday" title="calendar.firstweekday"><code class="xref py py-attr docutils literal notranslate"><span class="pre">firstweekday</span></code></a> property.</p>
  201. </dd></dl>
  202. <dl class="py method">
  203. <dt class="sig sig-object py" id="calendar.Calendar.itermonthdates">
  204. <span class="sig-name descname"><span class="pre">itermonthdates</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">year</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">month</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#calendar.Calendar.itermonthdates" title="Link to this definition">¶</a></dt>
  205. <dd><p>Return an iterator for the month <em>month</em> (1–12) in the year <em>year</em>. This
  206. iterator will return all days (as <a class="reference internal" href="datetime.html#datetime.date" title="datetime.date"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime.date</span></code></a> objects) for the
  207. month and all days before the start of the month or after the end of the
  208. month that are required to get a complete week.</p>
  209. </dd></dl>
  210. <dl class="py method">
  211. <dt class="sig sig-object py" id="calendar.Calendar.itermonthdays">
  212. <span class="sig-name descname"><span class="pre">itermonthdays</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">year</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">month</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#calendar.Calendar.itermonthdays" title="Link to this definition">¶</a></dt>
  213. <dd><p>Return an iterator for the month <em>month</em> in the year <em>year</em> similar to
  214. <a class="reference internal" href="#calendar.Calendar.itermonthdates" title="calendar.Calendar.itermonthdates"><code class="xref py py-meth docutils literal notranslate"><span class="pre">itermonthdates()</span></code></a>, but not restricted by the <a class="reference internal" href="datetime.html#datetime.date" title="datetime.date"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime.date</span></code></a>
  215. range. Days returned will simply be day of the month numbers. For the
  216. days outside of the specified month, the day number is <code class="docutils literal notranslate"><span class="pre">0</span></code>.</p>
  217. </dd></dl>
  218. <dl class="py method">
  219. <dt class="sig sig-object py" id="calendar.Calendar.itermonthdays2">
  220. <span class="sig-name descname"><span class="pre">itermonthdays2</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">year</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">month</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#calendar.Calendar.itermonthdays2" title="Link to this definition">¶</a></dt>
  221. <dd><p>Return an iterator for the month <em>month</em> in the year <em>year</em> similar to
  222. <a class="reference internal" href="#calendar.Calendar.itermonthdates" title="calendar.Calendar.itermonthdates"><code class="xref py py-meth docutils literal notranslate"><span class="pre">itermonthdates()</span></code></a>, but not restricted by the <a class="reference internal" href="datetime.html#datetime.date" title="datetime.date"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime.date</span></code></a>
  223. range. Days returned will be tuples consisting of a day of the month
  224. number and a week day number.</p>
  225. </dd></dl>
  226. <dl class="py method">
  227. <dt class="sig sig-object py" id="calendar.Calendar.itermonthdays3">
  228. <span class="sig-name descname"><span class="pre">itermonthdays3</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">year</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">month</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#calendar.Calendar.itermonthdays3" title="Link to this definition">¶</a></dt>
  229. <dd><p>Return an iterator for the month <em>month</em> in the year <em>year</em> similar to
  230. <a class="reference internal" href="#calendar.Calendar.itermonthdates" title="calendar.Calendar.itermonthdates"><code class="xref py py-meth docutils literal notranslate"><span class="pre">itermonthdates()</span></code></a>, but not restricted by the <a class="reference internal" href="datetime.html#datetime.date" title="datetime.date"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime.date</span></code></a>
  231. range. Days returned will be tuples consisting of a year, a month and a day
  232. of the month numbers.</p>
  233. <div class="versionadded">
  234. <p><span class="versionmodified added">New in version 3.7.</span></p>
  235. </div>
  236. </dd></dl>
  237. <dl class="py method">
  238. <dt class="sig sig-object py" id="calendar.Calendar.itermonthdays4">
  239. <span class="sig-name descname"><span class="pre">itermonthdays4</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">year</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">month</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#calendar.Calendar.itermonthdays4" title="Link to this definition">¶</a></dt>
  240. <dd><p>Return an iterator for the month <em>month</em> in the year <em>year</em> similar to
  241. <a class="reference internal" href="#calendar.Calendar.itermonthdates" title="calendar.Calendar.itermonthdates"><code class="xref py py-meth docutils literal notranslate"><span class="pre">itermonthdates()</span></code></a>, but not restricted by the <a class="reference internal" href="datetime.html#datetime.date" title="datetime.date"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime.date</span></code></a>
  242. range. Days returned will be tuples consisting of a year, a month, a day
  243. of the month, and a day of the week numbers.</p>
  244. <div class="versionadded">
  245. <p><span class="versionmodified added">New in version 3.7.</span></p>
  246. </div>
  247. </dd></dl>
  248. <dl class="py method">
  249. <dt class="sig sig-object py" id="calendar.Calendar.monthdatescalendar">
  250. <span class="sig-name descname"><span class="pre">monthdatescalendar</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">year</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">month</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#calendar.Calendar.monthdatescalendar" title="Link to this definition">¶</a></dt>
  251. <dd><p>Return a list of the weeks in the month <em>month</em> of the <em>year</em> as full
  252. weeks. Weeks are lists of seven <a class="reference internal" href="datetime.html#datetime.date" title="datetime.date"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime.date</span></code></a> objects.</p>
  253. </dd></dl>
  254. <dl class="py method">
  255. <dt class="sig sig-object py" id="calendar.Calendar.monthdays2calendar">
  256. <span class="sig-name descname"><span class="pre">monthdays2calendar</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">year</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">month</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#calendar.Calendar.monthdays2calendar" title="Link to this definition">¶</a></dt>
  257. <dd><p>Return a list of the weeks in the month <em>month</em> of the <em>year</em> as full
  258. weeks. Weeks are lists of seven tuples of day numbers and weekday
  259. numbers.</p>
  260. </dd></dl>
  261. <dl class="py method">
  262. <dt class="sig sig-object py" id="calendar.Calendar.monthdayscalendar">
  263. <span class="sig-name descname"><span class="pre">monthdayscalendar</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">year</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">month</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#calendar.Calendar.monthdayscalendar" title="Link to this definition">¶</a></dt>
  264. <dd><p>Return a list of the weeks in the month <em>month</em> of the <em>year</em> as full
  265. weeks. Weeks are lists of seven day numbers.</p>
  266. </dd></dl>
  267. <dl class="py method">
  268. <dt class="sig sig-object py" id="calendar.Calendar.yeardatescalendar">
  269. <span class="sig-name descname"><span class="pre">yeardatescalendar</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">year</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">width</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">3</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#calendar.Calendar.yeardatescalendar" title="Link to this definition">¶</a></dt>
  270. <dd><p>Return the data for the specified year ready for formatting. The return
  271. value is a list of month rows. Each month row contains up to <em>width</em>
  272. months (defaulting to 3). Each month contains between 4 and 6 weeks and
  273. each week contains 1–7 days. Days are <a class="reference internal" href="datetime.html#datetime.date" title="datetime.date"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime.date</span></code></a> objects.</p>
  274. </dd></dl>
  275. <dl class="py method">
  276. <dt class="sig sig-object py" id="calendar.Calendar.yeardays2calendar">
  277. <span class="sig-name descname"><span class="pre">yeardays2calendar</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">year</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">width</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">3</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#calendar.Calendar.yeardays2calendar" title="Link to this definition">¶</a></dt>
  278. <dd><p>Return the data for the specified year ready for formatting (similar to
  279. <a class="reference internal" href="#calendar.Calendar.yeardatescalendar" title="calendar.Calendar.yeardatescalendar"><code class="xref py py-meth docutils literal notranslate"><span class="pre">yeardatescalendar()</span></code></a>). Entries in the week lists are tuples of day
  280. numbers and weekday numbers. Day numbers outside this month are zero.</p>
  281. </dd></dl>
  282. <dl class="py method">
  283. <dt class="sig sig-object py" id="calendar.Calendar.yeardayscalendar">
  284. <span class="sig-name descname"><span class="pre">yeardayscalendar</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">year</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">width</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">3</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#calendar.Calendar.yeardayscalendar" title="Link to this definition">¶</a></dt>
  285. <dd><p>Return the data for the specified year ready for formatting (similar to
  286. <a class="reference internal" href="#calendar.Calendar.yeardatescalendar" title="calendar.Calendar.yeardatescalendar"><code class="xref py py-meth docutils literal notranslate"><span class="pre">yeardatescalendar()</span></code></a>). Entries in the week lists are day numbers. Day
  287. numbers outside this month are zero.</p>
  288. </dd></dl>
  289. </dd></dl>
  290. <dl class="py class">
  291. <dt class="sig sig-object py" id="calendar.TextCalendar">
  292. <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">calendar.</span></span><span class="sig-name descname"><span class="pre">TextCalendar</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">firstweekday</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#calendar.TextCalendar" title="Link to this definition">¶</a></dt>
  293. <dd><p>This class can be used to generate plain text calendars.</p>
  294. <p><a class="reference internal" href="#calendar.TextCalendar" title="calendar.TextCalendar"><code class="xref py py-class docutils literal notranslate"><span class="pre">TextCalendar</span></code></a> instances have the following methods:</p>
  295. <dl class="py method">
  296. <dt class="sig sig-object py" id="calendar.TextCalendar.formatmonth">
  297. <span class="sig-name descname"><span class="pre">formatmonth</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">theyear</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">themonth</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">w</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">l</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#calendar.TextCalendar.formatmonth" title="Link to this definition">¶</a></dt>
  298. <dd><p>Return a month’s calendar in a multi-line string. If <em>w</em> is provided, it
  299. specifies the width of the date columns, which are centered. If <em>l</em> is
  300. given, it specifies the number of lines that each week will use. Depends
  301. on the first weekday as specified in the constructor or set by the
  302. <a class="reference internal" href="#calendar.setfirstweekday" title="calendar.setfirstweekday"><code class="xref py py-meth docutils literal notranslate"><span class="pre">setfirstweekday()</span></code></a> method.</p>
  303. </dd></dl>
  304. <dl class="py method">
  305. <dt class="sig sig-object py" id="calendar.TextCalendar.prmonth">
  306. <span class="sig-name descname"><span class="pre">prmonth</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">theyear</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">themonth</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">w</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">l</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#calendar.TextCalendar.prmonth" title="Link to this definition">¶</a></dt>
  307. <dd><p>Print a month’s calendar as returned by <a class="reference internal" href="#calendar.TextCalendar.formatmonth" title="calendar.TextCalendar.formatmonth"><code class="xref py py-meth docutils literal notranslate"><span class="pre">formatmonth()</span></code></a>.</p>
  308. </dd></dl>
  309. <dl class="py method">
  310. <dt class="sig sig-object py" id="calendar.TextCalendar.formatyear">
  311. <span class="sig-name descname"><span class="pre">formatyear</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">theyear</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">w</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">2</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">l</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">1</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">c</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">6</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">m</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">3</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#calendar.TextCalendar.formatyear" title="Link to this definition">¶</a></dt>
  312. <dd><p>Return a <em>m</em>-column calendar for an entire year as a multi-line string.
  313. Optional parameters <em>w</em>, <em>l</em>, and <em>c</em> are for date column width, lines per
  314. week, and number of spaces between month columns, respectively. Depends on
  315. the first weekday as specified in the constructor or set by the
  316. <a class="reference internal" href="#calendar.setfirstweekday" title="calendar.setfirstweekday"><code class="xref py py-meth docutils literal notranslate"><span class="pre">setfirstweekday()</span></code></a> method. The earliest year for which a calendar
  317. can be generated is platform-dependent.</p>
  318. </dd></dl>
  319. <dl class="py method">
  320. <dt class="sig sig-object py" id="calendar.TextCalendar.pryear">
  321. <span class="sig-name descname"><span class="pre">pryear</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">theyear</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">w</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">2</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">l</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">1</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">c</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">6</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">m</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">3</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#calendar.TextCalendar.pryear" title="Link to this definition">¶</a></dt>
  322. <dd><p>Print the calendar for an entire year as returned by <a class="reference internal" href="#calendar.TextCalendar.formatyear" title="calendar.TextCalendar.formatyear"><code class="xref py py-meth docutils literal notranslate"><span class="pre">formatyear()</span></code></a>.</p>
  323. </dd></dl>
  324. </dd></dl>
  325. <dl class="py class">
  326. <dt class="sig sig-object py" id="calendar.HTMLCalendar">
  327. <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">calendar.</span></span><span class="sig-name descname"><span class="pre">HTMLCalendar</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">firstweekday</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#calendar.HTMLCalendar" title="Link to this definition">¶</a></dt>
  328. <dd><p>This class can be used to generate HTML calendars.</p>
  329. <p><code class="xref py py-class docutils literal notranslate"><span class="pre">HTMLCalendar</span></code> instances have the following methods:</p>
  330. <dl class="py method">
  331. <dt class="sig sig-object py" id="calendar.HTMLCalendar.formatmonth">
  332. <span class="sig-name descname"><span class="pre">formatmonth</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">theyear</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">themonth</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">withyear</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#calendar.HTMLCalendar.formatmonth" title="Link to this definition">¶</a></dt>
  333. <dd><p>Return a month’s calendar as an HTML table. If <em>withyear</em> is true the year
  334. will be included in the header, otherwise just the month name will be
  335. used.</p>
  336. </dd></dl>
  337. <dl class="py method">
  338. <dt class="sig sig-object py" id="calendar.HTMLCalendar.formatyear">
  339. <span class="sig-name descname"><span class="pre">formatyear</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">theyear</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">width</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">3</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#calendar.HTMLCalendar.formatyear" title="Link to this definition">¶</a></dt>
  340. <dd><p>Return a year’s calendar as an HTML table. <em>width</em> (defaulting to 3)
  341. specifies the number of months per row.</p>
  342. </dd></dl>
  343. <dl class="py method">
  344. <dt class="sig sig-object py" id="calendar.HTMLCalendar.formatyearpage">
  345. <span class="sig-name descname"><span class="pre">formatyearpage</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">theyear</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">width</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">3</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">css</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'calendar.css'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">encoding</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#calendar.HTMLCalendar.formatyearpage" title="Link to this definition">¶</a></dt>
  346. <dd><p>Return a year’s calendar as a complete HTML page. <em>width</em> (defaulting to
  347. 3) specifies the number of months per row. <em>css</em> is the name for the
  348. cascading style sheet to be used. <a class="reference internal" href="constants.html#None" title="None"><code class="xref py py-const docutils literal notranslate"><span class="pre">None</span></code></a> can be passed if no style
  349. sheet should be used. <em>encoding</em> specifies the encoding to be used for the
  350. output (defaulting to the system default encoding).</p>
  351. </dd></dl>
  352. <dl class="py method">
  353. <dt class="sig sig-object py" id="calendar.HTMLCalendar.formatmonthname">
  354. <span class="sig-name descname"><span class="pre">formatmonthname</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">theyear</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">themonth</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">withyear</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#calendar.HTMLCalendar.formatmonthname" title="Link to this definition">¶</a></dt>
  355. <dd><p>Return a month name as an HTML table row. If <em>withyear</em> is true the year
  356. will be included in the row, otherwise just the month name will be
  357. used.</p>
  358. </dd></dl>
  359. <p><code class="xref py py-class docutils literal notranslate"><span class="pre">HTMLCalendar</span></code> has the following attributes you can override to
  360. customize the CSS classes used by the calendar:</p>
  361. <dl class="py attribute">
  362. <dt class="sig sig-object py" id="calendar.HTMLCalendar.cssclasses">
  363. <span class="sig-name descname"><span class="pre">cssclasses</span></span><a class="headerlink" href="#calendar.HTMLCalendar.cssclasses" title="Link to this definition">¶</a></dt>
  364. <dd><p>A list of CSS classes used for each weekday. The default class list is:</p>
  365. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">cssclasses</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;mon&quot;</span><span class="p">,</span> <span class="s2">&quot;tue&quot;</span><span class="p">,</span> <span class="s2">&quot;wed&quot;</span><span class="p">,</span> <span class="s2">&quot;thu&quot;</span><span class="p">,</span> <span class="s2">&quot;fri&quot;</span><span class="p">,</span> <span class="s2">&quot;sat&quot;</span><span class="p">,</span> <span class="s2">&quot;sun&quot;</span><span class="p">]</span>
  366. </pre></div>
  367. </div>
  368. <p>more styles can be added for each day:</p>
  369. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">cssclasses</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;mon text-bold&quot;</span><span class="p">,</span> <span class="s2">&quot;tue&quot;</span><span class="p">,</span> <span class="s2">&quot;wed&quot;</span><span class="p">,</span> <span class="s2">&quot;thu&quot;</span><span class="p">,</span> <span class="s2">&quot;fri&quot;</span><span class="p">,</span> <span class="s2">&quot;sat&quot;</span><span class="p">,</span> <span class="s2">&quot;sun red&quot;</span><span class="p">]</span>
  370. </pre></div>
  371. </div>
  372. <p>Note that the length of this list must be seven items.</p>
  373. </dd></dl>
  374. <dl class="py attribute">
  375. <dt class="sig sig-object py" id="calendar.HTMLCalendar.cssclass_noday">
  376. <span class="sig-name descname"><span class="pre">cssclass_noday</span></span><a class="headerlink" href="#calendar.HTMLCalendar.cssclass_noday" title="Link to this definition">¶</a></dt>
  377. <dd><p>The CSS class for a weekday occurring in the previous or coming month.</p>
  378. <div class="versionadded">
  379. <p><span class="versionmodified added">New in version 3.7.</span></p>
  380. </div>
  381. </dd></dl>
  382. <dl class="py attribute">
  383. <dt class="sig sig-object py" id="calendar.HTMLCalendar.cssclasses_weekday_head">
  384. <span class="sig-name descname"><span class="pre">cssclasses_weekday_head</span></span><a class="headerlink" href="#calendar.HTMLCalendar.cssclasses_weekday_head" title="Link to this definition">¶</a></dt>
  385. <dd><p>A list of CSS classes used for weekday names in the header row.
  386. The default is the same as <a class="reference internal" href="#calendar.HTMLCalendar.cssclasses" title="calendar.HTMLCalendar.cssclasses"><code class="xref py py-attr docutils literal notranslate"><span class="pre">cssclasses</span></code></a>.</p>
  387. <div class="versionadded">
  388. <p><span class="versionmodified added">New in version 3.7.</span></p>
  389. </div>
  390. </dd></dl>
  391. <dl class="py attribute">
  392. <dt class="sig sig-object py" id="calendar.HTMLCalendar.cssclass_month_head">
  393. <span class="sig-name descname"><span class="pre">cssclass_month_head</span></span><a class="headerlink" href="#calendar.HTMLCalendar.cssclass_month_head" title="Link to this definition">¶</a></dt>
  394. <dd><p>The month’s head CSS class (used by <a class="reference internal" href="#calendar.HTMLCalendar.formatmonthname" title="calendar.HTMLCalendar.formatmonthname"><code class="xref py py-meth docutils literal notranslate"><span class="pre">formatmonthname()</span></code></a>).
  395. The default value is <code class="docutils literal notranslate"><span class="pre">&quot;month&quot;</span></code>.</p>
  396. <div class="versionadded">
  397. <p><span class="versionmodified added">New in version 3.7.</span></p>
  398. </div>
  399. </dd></dl>
  400. <dl class="py attribute">
  401. <dt class="sig sig-object py" id="calendar.HTMLCalendar.cssclass_month">
  402. <span class="sig-name descname"><span class="pre">cssclass_month</span></span><a class="headerlink" href="#calendar.HTMLCalendar.cssclass_month" title="Link to this definition">¶</a></dt>
  403. <dd><p>The CSS class for the whole month’s table (used by <a class="reference internal" href="#calendar.HTMLCalendar.formatmonth" title="calendar.HTMLCalendar.formatmonth"><code class="xref py py-meth docutils literal notranslate"><span class="pre">formatmonth()</span></code></a>).
  404. The default value is <code class="docutils literal notranslate"><span class="pre">&quot;month&quot;</span></code>.</p>
  405. <div class="versionadded">
  406. <p><span class="versionmodified added">New in version 3.7.</span></p>
  407. </div>
  408. </dd></dl>
  409. <dl class="py attribute">
  410. <dt class="sig sig-object py" id="calendar.HTMLCalendar.cssclass_year">
  411. <span class="sig-name descname"><span class="pre">cssclass_year</span></span><a class="headerlink" href="#calendar.HTMLCalendar.cssclass_year" title="Link to this definition">¶</a></dt>
  412. <dd><p>The CSS class for the whole year’s table of tables (used by
  413. <a class="reference internal" href="#calendar.HTMLCalendar.formatyear" title="calendar.HTMLCalendar.formatyear"><code class="xref py py-meth docutils literal notranslate"><span class="pre">formatyear()</span></code></a>). The default value is <code class="docutils literal notranslate"><span class="pre">&quot;year&quot;</span></code>.</p>
  414. <div class="versionadded">
  415. <p><span class="versionmodified added">New in version 3.7.</span></p>
  416. </div>
  417. </dd></dl>
  418. <dl class="py attribute">
  419. <dt class="sig sig-object py" id="calendar.HTMLCalendar.cssclass_year_head">
  420. <span class="sig-name descname"><span class="pre">cssclass_year_head</span></span><a class="headerlink" href="#calendar.HTMLCalendar.cssclass_year_head" title="Link to this definition">¶</a></dt>
  421. <dd><p>The CSS class for the table head for the whole year (used by
  422. <a class="reference internal" href="#calendar.HTMLCalendar.formatyear" title="calendar.HTMLCalendar.formatyear"><code class="xref py py-meth docutils literal notranslate"><span class="pre">formatyear()</span></code></a>). The default value is <code class="docutils literal notranslate"><span class="pre">&quot;year&quot;</span></code>.</p>
  423. <div class="versionadded">
  424. <p><span class="versionmodified added">New in version 3.7.</span></p>
  425. </div>
  426. </dd></dl>
  427. <p>Note that although the naming for the above described class attributes is
  428. singular (e.g. <code class="docutils literal notranslate"><span class="pre">cssclass_month</span></code> <code class="docutils literal notranslate"><span class="pre">cssclass_noday</span></code>), one can replace the
  429. single CSS class with a space separated list of CSS classes, for example:</p>
  430. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="s2">&quot;text-bold text-red&quot;</span>
  431. </pre></div>
  432. </div>
  433. <p>Here is an example how <code class="xref py py-class docutils literal notranslate"><span class="pre">HTMLCalendar</span></code> can be customized:</p>
  434. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">CustomHTMLCal</span><span class="p">(</span><span class="n">calendar</span><span class="o">.</span><span class="n">HTMLCalendar</span><span class="p">):</span>
  435. <span class="n">cssclasses</span> <span class="o">=</span> <span class="p">[</span><span class="n">style</span> <span class="o">+</span> <span class="s2">&quot; text-nowrap&quot;</span> <span class="k">for</span> <span class="n">style</span> <span class="ow">in</span>
  436. <span class="n">calendar</span><span class="o">.</span><span class="n">HTMLCalendar</span><span class="o">.</span><span class="n">cssclasses</span><span class="p">]</span>
  437. <span class="n">cssclass_month_head</span> <span class="o">=</span> <span class="s2">&quot;text-center month-head&quot;</span>
  438. <span class="n">cssclass_month</span> <span class="o">=</span> <span class="s2">&quot;text-center month&quot;</span>
  439. <span class="n">cssclass_year</span> <span class="o">=</span> <span class="s2">&quot;text-italic lead&quot;</span>
  440. </pre></div>
  441. </div>
  442. </dd></dl>
  443. <dl class="py class">
  444. <dt class="sig sig-object py" id="calendar.LocaleTextCalendar">
  445. <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">calendar.</span></span><span class="sig-name descname"><span class="pre">LocaleTextCalendar</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">firstweekday</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">locale</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#calendar.LocaleTextCalendar" title="Link to this definition">¶</a></dt>
  446. <dd><p>This subclass of <a class="reference internal" href="#calendar.TextCalendar" title="calendar.TextCalendar"><code class="xref py py-class docutils literal notranslate"><span class="pre">TextCalendar</span></code></a> can be passed a locale name in the
  447. constructor and will return month and weekday names in the specified locale.</p>
  448. </dd></dl>
  449. <dl class="py class">
  450. <dt class="sig sig-object py" id="calendar.LocaleHTMLCalendar">
  451. <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">calendar.</span></span><span class="sig-name descname"><span class="pre">LocaleHTMLCalendar</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">firstweekday</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">locale</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#calendar.LocaleHTMLCalendar" title="Link to this definition">¶</a></dt>
  452. <dd><p>This subclass of <a class="reference internal" href="#calendar.HTMLCalendar" title="calendar.HTMLCalendar"><code class="xref py py-class docutils literal notranslate"><span class="pre">HTMLCalendar</span></code></a> can be passed a locale name in the
  453. constructor and will return month and weekday names in the specified
  454. locale.</p>
  455. </dd></dl>
  456. <div class="admonition note">
  457. <p class="admonition-title">Note</p>
  458. <p>The constructor, <code class="xref py py-meth docutils literal notranslate"><span class="pre">formatweekday()</span></code> and <code class="xref py py-meth docutils literal notranslate"><span class="pre">formatmonthname()</span></code> methods
  459. of these two classes temporarily change the <code class="docutils literal notranslate"><span class="pre">LC_TIME</span></code> locale to the given
  460. <em>locale</em>. Because the current locale is a process-wide setting, they are
  461. not thread-safe.</p>
  462. </div>
  463. <p>For simple text calendars this module provides the following functions.</p>
  464. <dl class="py function">
  465. <dt class="sig sig-object py" id="calendar.setfirstweekday">
  466. <span class="sig-prename descclassname"><span class="pre">calendar.</span></span><span class="sig-name descname"><span class="pre">setfirstweekday</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">weekday</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#calendar.setfirstweekday" title="Link to this definition">¶</a></dt>
  467. <dd><p>Sets the weekday (<code class="docutils literal notranslate"><span class="pre">0</span></code> is Monday, <code class="docutils literal notranslate"><span class="pre">6</span></code> is Sunday) to start each week. The
  468. values <a class="reference internal" href="#calendar.MONDAY" title="calendar.MONDAY"><code class="xref py py-const docutils literal notranslate"><span class="pre">MONDAY</span></code></a>, <a class="reference internal" href="#calendar.TUESDAY" title="calendar.TUESDAY"><code class="xref py py-const docutils literal notranslate"><span class="pre">TUESDAY</span></code></a>, <a class="reference internal" href="#calendar.WEDNESDAY" title="calendar.WEDNESDAY"><code class="xref py py-const docutils literal notranslate"><span class="pre">WEDNESDAY</span></code></a>, <a class="reference internal" href="#calendar.THURSDAY" title="calendar.THURSDAY"><code class="xref py py-const docutils literal notranslate"><span class="pre">THURSDAY</span></code></a>,
  469. <a class="reference internal" href="#calendar.FRIDAY" title="calendar.FRIDAY"><code class="xref py py-const docutils literal notranslate"><span class="pre">FRIDAY</span></code></a>, <a class="reference internal" href="#calendar.SATURDAY" title="calendar.SATURDAY"><code class="xref py py-const docutils literal notranslate"><span class="pre">SATURDAY</span></code></a>, and <a class="reference internal" href="#calendar.SUNDAY" title="calendar.SUNDAY"><code class="xref py py-const docutils literal notranslate"><span class="pre">SUNDAY</span></code></a> are provided for
  470. convenience. For example, to set the first weekday to Sunday:</p>
  471. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">calendar</span>
  472. <span class="n">calendar</span><span class="o">.</span><span class="n">setfirstweekday</span><span class="p">(</span><span class="n">calendar</span><span class="o">.</span><span class="n">SUNDAY</span><span class="p">)</span>
  473. </pre></div>
  474. </div>
  475. </dd></dl>
  476. <dl class="py function">
  477. <dt class="sig sig-object py" id="calendar.firstweekday">
  478. <span class="sig-prename descclassname"><span class="pre">calendar.</span></span><span class="sig-name descname"><span class="pre">firstweekday</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#calendar.firstweekday" title="Link to this definition">¶</a></dt>
  479. <dd><p>Returns the current setting for the weekday to start each week.</p>
  480. </dd></dl>
  481. <dl class="py function">
  482. <dt class="sig sig-object py" id="calendar.isleap">
  483. <span class="sig-prename descclassname"><span class="pre">calendar.</span></span><span class="sig-name descname"><span class="pre">isleap</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">year</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#calendar.isleap" title="Link to this definition">¶</a></dt>
  484. <dd><p>Returns <a class="reference internal" href="constants.html#True" title="True"><code class="xref py py-const docutils literal notranslate"><span class="pre">True</span></code></a> if <em>year</em> is a leap year, otherwise <a class="reference internal" href="constants.html#False" title="False"><code class="xref py py-const docutils literal notranslate"><span class="pre">False</span></code></a>.</p>
  485. </dd></dl>
  486. <dl class="py function">
  487. <dt class="sig sig-object py" id="calendar.leapdays">
  488. <span class="sig-prename descclassname"><span class="pre">calendar.</span></span><span class="sig-name descname"><span class="pre">leapdays</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">y1</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">y2</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#calendar.leapdays" title="Link to this definition">¶</a></dt>
  489. <dd><p>Returns the number of leap years in the range from <em>y1</em> to <em>y2</em> (exclusive),
  490. where <em>y1</em> and <em>y2</em> are years.</p>
  491. <p>This function works for ranges spanning a century change.</p>
  492. </dd></dl>
  493. <dl class="py function">
  494. <dt class="sig sig-object py" id="calendar.weekday">
  495. <span class="sig-prename descclassname"><span class="pre">calendar.</span></span><span class="sig-name descname"><span class="pre">weekday</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">year</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">month</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">day</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#calendar.weekday" title="Link to this definition">¶</a></dt>
  496. <dd><p>Returns the day of the week (<code class="docutils literal notranslate"><span class="pre">0</span></code> is Monday) for <em>year</em> (<code class="docutils literal notranslate"><span class="pre">1970</span></code>–…),
  497. <em>month</em> (<code class="docutils literal notranslate"><span class="pre">1</span></code>–<code class="docutils literal notranslate"><span class="pre">12</span></code>), <em>day</em> (<code class="docutils literal notranslate"><span class="pre">1</span></code>–<code class="docutils literal notranslate"><span class="pre">31</span></code>).</p>
  498. </dd></dl>
  499. <dl class="py function">
  500. <dt class="sig sig-object py" id="calendar.weekheader">
  501. <span class="sig-prename descclassname"><span class="pre">calendar.</span></span><span class="sig-name descname"><span class="pre">weekheader</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">n</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#calendar.weekheader" title="Link to this definition">¶</a></dt>
  502. <dd><p>Return a header containing abbreviated weekday names. <em>n</em> specifies the width in
  503. characters for one weekday.</p>
  504. </dd></dl>
  505. <dl class="py function">
  506. <dt class="sig sig-object py" id="calendar.monthrange">
  507. <span class="sig-prename descclassname"><span class="pre">calendar.</span></span><span class="sig-name descname"><span class="pre">monthrange</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">year</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">month</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#calendar.monthrange" title="Link to this definition">¶</a></dt>
  508. <dd><p>Returns weekday of first day of the month and number of days in month, for the
  509. specified <em>year</em> and <em>month</em>.</p>
  510. </dd></dl>
  511. <dl class="py function">
  512. <dt class="sig sig-object py" id="calendar.monthcalendar">
  513. <span class="sig-prename descclassname"><span class="pre">calendar.</span></span><span class="sig-name descname"><span class="pre">monthcalendar</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">year</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">month</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#calendar.monthcalendar" title="Link to this definition">¶</a></dt>
  514. <dd><p>Returns a matrix representing a month’s calendar. Each row represents a week;
  515. days outside of the month are represented by zeros. Each week begins with Monday
  516. unless set by <a class="reference internal" href="#calendar.setfirstweekday" title="calendar.setfirstweekday"><code class="xref py py-func docutils literal notranslate"><span class="pre">setfirstweekday()</span></code></a>.</p>
  517. </dd></dl>
  518. <dl class="py function">
  519. <dt class="sig sig-object py" id="calendar.prmonth">
  520. <span class="sig-prename descclassname"><span class="pre">calendar.</span></span><span class="sig-name descname"><span class="pre">prmonth</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">theyear</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">themonth</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">w</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">l</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#calendar.prmonth" title="Link to this definition">¶</a></dt>
  521. <dd><p>Prints a month’s calendar as returned by <a class="reference internal" href="#calendar.month" title="calendar.month"><code class="xref py py-func docutils literal notranslate"><span class="pre">month()</span></code></a>.</p>
  522. </dd></dl>
  523. <dl class="py function">
  524. <dt class="sig sig-object py" id="calendar.month">
  525. <span class="sig-prename descclassname"><span class="pre">calendar.</span></span><span class="sig-name descname"><span class="pre">month</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">theyear</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">themonth</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">w</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">l</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#calendar.month" title="Link to this definition">¶</a></dt>
  526. <dd><p>Returns a month’s calendar in a multi-line string using the <a class="reference internal" href="#calendar.TextCalendar.formatmonth" title="calendar.TextCalendar.formatmonth"><code class="xref py py-meth docutils literal notranslate"><span class="pre">formatmonth()</span></code></a>
  527. of the <a class="reference internal" href="#calendar.TextCalendar" title="calendar.TextCalendar"><code class="xref py py-class docutils literal notranslate"><span class="pre">TextCalendar</span></code></a> class.</p>
  528. </dd></dl>
  529. <dl class="py function">
  530. <dt class="sig sig-object py" id="calendar.prcal">
  531. <span class="sig-prename descclassname"><span class="pre">calendar.</span></span><span class="sig-name descname"><span class="pre">prcal</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">year</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">w</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">l</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">c</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">6</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">m</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">3</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#calendar.prcal" title="Link to this definition">¶</a></dt>
  532. <dd><p>Prints the calendar for an entire year as returned by <a class="reference internal" href="#module-calendar" title="calendar: Functions for working with calendars, including some emulation of the Unix cal program."><code class="xref py py-func docutils literal notranslate"><span class="pre">calendar()</span></code></a>.</p>
  533. </dd></dl>
  534. <dl class="py function">
  535. <dt class="sig sig-object py" id="calendar.calendar">
  536. <span class="sig-prename descclassname"><span class="pre">calendar.</span></span><span class="sig-name descname"><span class="pre">calendar</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">year</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">w</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">2</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">l</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">1</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">c</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">6</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">m</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">3</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#calendar.calendar" title="Link to this definition">¶</a></dt>
  537. <dd><p>Returns a 3-column calendar for an entire year as a multi-line string using
  538. the <a class="reference internal" href="#calendar.TextCalendar.formatyear" title="calendar.TextCalendar.formatyear"><code class="xref py py-meth docutils literal notranslate"><span class="pre">formatyear()</span></code></a> of the <a class="reference internal" href="#calendar.TextCalendar" title="calendar.TextCalendar"><code class="xref py py-class docutils literal notranslate"><span class="pre">TextCalendar</span></code></a> class.</p>
  539. </dd></dl>
  540. <dl class="py function">
  541. <dt class="sig sig-object py" id="calendar.timegm">
  542. <span class="sig-prename descclassname"><span class="pre">calendar.</span></span><span class="sig-name descname"><span class="pre">timegm</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">tuple</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#calendar.timegm" title="Link to this definition">¶</a></dt>
  543. <dd><p>An unrelated but handy function that takes a time tuple such as returned by
  544. the <a class="reference internal" href="time.html#time.gmtime" title="time.gmtime"><code class="xref py py-func docutils literal notranslate"><span class="pre">gmtime()</span></code></a> function in the <a class="reference internal" href="time.html#module-time" title="time: Time access and conversions."><code class="xref py py-mod docutils literal notranslate"><span class="pre">time</span></code></a> module, and returns the
  545. corresponding Unix timestamp value, assuming an epoch of 1970, and the POSIX
  546. encoding. In fact, <a class="reference internal" href="time.html#time.gmtime" title="time.gmtime"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.gmtime()</span></code></a> and <a class="reference internal" href="#calendar.timegm" title="calendar.timegm"><code class="xref py py-func docutils literal notranslate"><span class="pre">timegm()</span></code></a> are each others’
  547. inverse.</p>
  548. </dd></dl>
  549. <p>The <a class="reference internal" href="#module-calendar" title="calendar: Functions for working with calendars, including some emulation of the Unix cal program."><code class="xref py py-mod docutils literal notranslate"><span class="pre">calendar</span></code></a> module exports the following data attributes:</p>
  550. <dl class="py data">
  551. <dt class="sig sig-object py" id="calendar.day_name">
  552. <span class="sig-prename descclassname"><span class="pre">calendar.</span></span><span class="sig-name descname"><span class="pre">day_name</span></span><a class="headerlink" href="#calendar.day_name" title="Link to this definition">¶</a></dt>
  553. <dd><p>An array that represents the days of the week in the current locale.</p>
  554. </dd></dl>
  555. <dl class="py data">
  556. <dt class="sig sig-object py" id="calendar.day_abbr">
  557. <span class="sig-prename descclassname"><span class="pre">calendar.</span></span><span class="sig-name descname"><span class="pre">day_abbr</span></span><a class="headerlink" href="#calendar.day_abbr" title="Link to this definition">¶</a></dt>
  558. <dd><p>An array that represents the abbreviated days of the week in the current locale.</p>
  559. </dd></dl>
  560. <dl class="py data">
  561. <dt class="sig sig-object py" id="calendar.MONDAY">
  562. <span class="sig-prename descclassname"><span class="pre">calendar.</span></span><span class="sig-name descname"><span class="pre">MONDAY</span></span><a class="headerlink" href="#calendar.MONDAY" title="Link to this definition">¶</a></dt>
  563. <dt class="sig sig-object py" id="calendar.TUESDAY">
  564. <span class="sig-prename descclassname"><span class="pre">calendar.</span></span><span class="sig-name descname"><span class="pre">TUESDAY</span></span><a class="headerlink" href="#calendar.TUESDAY" title="Link to this definition">¶</a></dt>
  565. <dt class="sig sig-object py" id="calendar.WEDNESDAY">
  566. <span class="sig-prename descclassname"><span class="pre">calendar.</span></span><span class="sig-name descname"><span class="pre">WEDNESDAY</span></span><a class="headerlink" href="#calendar.WEDNESDAY" title="Link to this definition">¶</a></dt>
  567. <dt class="sig sig-object py" id="calendar.THURSDAY">
  568. <span class="sig-prename descclassname"><span class="pre">calendar.</span></span><span class="sig-name descname"><span class="pre">THURSDAY</span></span><a class="headerlink" href="#calendar.THURSDAY" title="Link to this definition">¶</a></dt>
  569. <dt class="sig sig-object py" id="calendar.FRIDAY">
  570. <span class="sig-prename descclassname"><span class="pre">calendar.</span></span><span class="sig-name descname"><span class="pre">FRIDAY</span></span><a class="headerlink" href="#calendar.FRIDAY" title="Link to this definition">¶</a></dt>
  571. <dt class="sig sig-object py" id="calendar.SATURDAY">
  572. <span class="sig-prename descclassname"><span class="pre">calendar.</span></span><span class="sig-name descname"><span class="pre">SATURDAY</span></span><a class="headerlink" href="#calendar.SATURDAY" title="Link to this definition">¶</a></dt>
  573. <dt class="sig sig-object py" id="calendar.SUNDAY">
  574. <span class="sig-prename descclassname"><span class="pre">calendar.</span></span><span class="sig-name descname"><span class="pre">SUNDAY</span></span><a class="headerlink" href="#calendar.SUNDAY" title="Link to this definition">¶</a></dt>
  575. <dd><p>Aliases for the days of the week,
  576. where <code class="docutils literal notranslate"><span class="pre">MONDAY</span></code> is <code class="docutils literal notranslate"><span class="pre">0</span></code> and <code class="docutils literal notranslate"><span class="pre">SUNDAY</span></code> is <code class="docutils literal notranslate"><span class="pre">6</span></code>.</p>
  577. <div class="versionadded">
  578. <p><span class="versionmodified added">New in version 3.12.</span></p>
  579. </div>
  580. </dd></dl>
  581. <dl class="py class">
  582. <dt class="sig sig-object py" id="calendar.Day">
  583. <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">calendar.</span></span><span class="sig-name descname"><span class="pre">Day</span></span><a class="headerlink" href="#calendar.Day" title="Link to this definition">¶</a></dt>
  584. <dd><p>Enumeration defining days of the week as integer constants.
  585. The members of this enumeration are exported to the module scope as
  586. <a class="reference internal" href="#calendar.MONDAY" title="calendar.MONDAY"><code class="xref py py-data docutils literal notranslate"><span class="pre">MONDAY</span></code></a> through <a class="reference internal" href="#calendar.SUNDAY" title="calendar.SUNDAY"><code class="xref py py-data docutils literal notranslate"><span class="pre">SUNDAY</span></code></a>.</p>
  587. <div class="versionadded">
  588. <p><span class="versionmodified added">New in version 3.12.</span></p>
  589. </div>
  590. </dd></dl>
  591. <dl class="py data">
  592. <dt class="sig sig-object py" id="calendar.month_name">
  593. <span class="sig-prename descclassname"><span class="pre">calendar.</span></span><span class="sig-name descname"><span class="pre">month_name</span></span><a class="headerlink" href="#calendar.month_name" title="Link to this definition">¶</a></dt>
  594. <dd><p>An array that represents the months of the year in the current locale. This
  595. follows normal convention of January being month number 1, so it has a length of
  596. 13 and <code class="docutils literal notranslate"><span class="pre">month_name[0]</span></code> is the empty string.</p>
  597. </dd></dl>
  598. <dl class="py data">
  599. <dt class="sig sig-object py" id="calendar.month_abbr">
  600. <span class="sig-prename descclassname"><span class="pre">calendar.</span></span><span class="sig-name descname"><span class="pre">month_abbr</span></span><a class="headerlink" href="#calendar.month_abbr" title="Link to this definition">¶</a></dt>
  601. <dd><p>An array that represents the abbreviated months of the year in the current
  602. locale. This follows normal convention of January being month number 1, so it
  603. has a length of 13 and <code class="docutils literal notranslate"><span class="pre">month_abbr[0]</span></code> is the empty string.</p>
  604. </dd></dl>
  605. <dl class="py data">
  606. <dt class="sig sig-object py" id="calendar.JANUARY">
  607. <span class="sig-prename descclassname"><span class="pre">calendar.</span></span><span class="sig-name descname"><span class="pre">JANUARY</span></span><a class="headerlink" href="#calendar.JANUARY" title="Link to this definition">¶</a></dt>
  608. <dt class="sig sig-object py" id="calendar.FEBRUARY">
  609. <span class="sig-prename descclassname"><span class="pre">calendar.</span></span><span class="sig-name descname"><span class="pre">FEBRUARY</span></span><a class="headerlink" href="#calendar.FEBRUARY" title="Link to this definition">¶</a></dt>
  610. <dt class="sig sig-object py" id="calendar.MARCH">
  611. <span class="sig-prename descclassname"><span class="pre">calendar.</span></span><span class="sig-name descname"><span class="pre">MARCH</span></span><a class="headerlink" href="#calendar.MARCH" title="Link to this definition">¶</a></dt>
  612. <dt class="sig sig-object py" id="calendar.APRIL">
  613. <span class="sig-prename descclassname"><span class="pre">calendar.</span></span><span class="sig-name descname"><span class="pre">APRIL</span></span><a class="headerlink" href="#calendar.APRIL" title="Link to this definition">¶</a></dt>
  614. <dt class="sig sig-object py" id="calendar.MAY">
  615. <span class="sig-prename descclassname"><span class="pre">calendar.</span></span><span class="sig-name descname"><span class="pre">MAY</span></span><a class="headerlink" href="#calendar.MAY" title="Link to this definition">¶</a></dt>
  616. <dt class="sig sig-object py" id="calendar.JUNE">
  617. <span class="sig-prename descclassname"><span class="pre">calendar.</span></span><span class="sig-name descname"><span class="pre">JUNE</span></span><a class="headerlink" href="#calendar.JUNE" title="Link to this definition">¶</a></dt>
  618. <dt class="sig sig-object py" id="calendar.JULY">
  619. <span class="sig-prename descclassname"><span class="pre">calendar.</span></span><span class="sig-name descname"><span class="pre">JULY</span></span><a class="headerlink" href="#calendar.JULY" title="Link to this definition">¶</a></dt>
  620. <dt class="sig sig-object py" id="calendar.AUGUST">
  621. <span class="sig-prename descclassname"><span class="pre">calendar.</span></span><span class="sig-name descname"><span class="pre">AUGUST</span></span><a class="headerlink" href="#calendar.AUGUST" title="Link to this definition">¶</a></dt>
  622. <dt class="sig sig-object py" id="calendar.SEPTEMBER">
  623. <span class="sig-prename descclassname"><span class="pre">calendar.</span></span><span class="sig-name descname"><span class="pre">SEPTEMBER</span></span><a class="headerlink" href="#calendar.SEPTEMBER" title="Link to this definition">¶</a></dt>
  624. <dt class="sig sig-object py" id="calendar.OCTOBER">
  625. <span class="sig-prename descclassname"><span class="pre">calendar.</span></span><span class="sig-name descname"><span class="pre">OCTOBER</span></span><a class="headerlink" href="#calendar.OCTOBER" title="Link to this definition">¶</a></dt>
  626. <dt class="sig sig-object py" id="calendar.NOVEMBER">
  627. <span class="sig-prename descclassname"><span class="pre">calendar.</span></span><span class="sig-name descname"><span class="pre">NOVEMBER</span></span><a class="headerlink" href="#calendar.NOVEMBER" title="Link to this definition">¶</a></dt>
  628. <dt class="sig sig-object py" id="calendar.DECEMBER">
  629. <span class="sig-prename descclassname"><span class="pre">calendar.</span></span><span class="sig-name descname"><span class="pre">DECEMBER</span></span><a class="headerlink" href="#calendar.DECEMBER" title="Link to this definition">¶</a></dt>
  630. <dd><p>Aliases for the months of the year,
  631. where <code class="docutils literal notranslate"><span class="pre">JANUARY</span></code> is <code class="docutils literal notranslate"><span class="pre">1</span></code> and <code class="docutils literal notranslate"><span class="pre">DECEMBER</span></code> is <code class="docutils literal notranslate"><span class="pre">12</span></code>.</p>
  632. <div class="versionadded">
  633. <p><span class="versionmodified added">New in version 3.12.</span></p>
  634. </div>
  635. </dd></dl>
  636. <dl class="py class">
  637. <dt class="sig sig-object py" id="calendar.Month">
  638. <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">calendar.</span></span><span class="sig-name descname"><span class="pre">Month</span></span><a class="headerlink" href="#calendar.Month" title="Link to this definition">¶</a></dt>
  639. <dd><p>Enumeration defining months of the year as integer constants.
  640. The members of this enumeration are exported to the module scope as
  641. <a class="reference internal" href="#calendar.JANUARY" title="calendar.JANUARY"><code class="xref py py-data docutils literal notranslate"><span class="pre">JANUARY</span></code></a> through <a class="reference internal" href="#calendar.DECEMBER" title="calendar.DECEMBER"><code class="xref py py-data docutils literal notranslate"><span class="pre">DECEMBER</span></code></a>.</p>
  642. <div class="versionadded">
  643. <p><span class="versionmodified added">New in version 3.12.</span></p>
  644. </div>
  645. </dd></dl>
  646. <p>The <a class="reference internal" href="#module-calendar" title="calendar: Functions for working with calendars, including some emulation of the Unix cal program."><code class="xref py py-mod docutils literal notranslate"><span class="pre">calendar</span></code></a> module defines the following exceptions:</p>
  647. <dl class="py exception">
  648. <dt class="sig sig-object py" id="calendar.IllegalMonthError">
  649. <em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">calendar.</span></span><span class="sig-name descname"><span class="pre">IllegalMonthError</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">month</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#calendar.IllegalMonthError" title="Link to this definition">¶</a></dt>
  650. <dd><p>A subclass of <a class="reference internal" href="exceptions.html#ValueError" title="ValueError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code></a>,
  651. raised when the given month number is outside of the range 1-12 (inclusive).</p>
  652. <dl class="py attribute">
  653. <dt class="sig sig-object py" id="calendar.IllegalMonthError.month">
  654. <span class="sig-name descname"><span class="pre">month</span></span><a class="headerlink" href="#calendar.IllegalMonthError.month" title="Link to this definition">¶</a></dt>
  655. <dd><p>The invalid month number.</p>
  656. </dd></dl>
  657. </dd></dl>
  658. <dl class="py exception">
  659. <dt class="sig sig-object py" id="calendar.IllegalWeekdayError">
  660. <em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">calendar.</span></span><span class="sig-name descname"><span class="pre">IllegalWeekdayError</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">weekday</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#calendar.IllegalWeekdayError" title="Link to this definition">¶</a></dt>
  661. <dd><p>A subclass of <a class="reference internal" href="exceptions.html#ValueError" title="ValueError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code></a>,
  662. raised when the given weekday number is outside of the range 0-6 (inclusive).</p>
  663. <dl class="py attribute">
  664. <dt class="sig sig-object py" id="calendar.IllegalWeekdayError.weekday">
  665. <span class="sig-name descname"><span class="pre">weekday</span></span><a class="headerlink" href="#calendar.IllegalWeekdayError.weekday" title="Link to this definition">¶</a></dt>
  666. <dd><p>The invalid weekday number.</p>
  667. </dd></dl>
  668. </dd></dl>
  669. <div class="admonition seealso">
  670. <p class="admonition-title">See also</p>
  671. <dl class="simple">
  672. <dt>Module <a class="reference internal" href="datetime.html#module-datetime" title="datetime: Basic date and time types."><code class="xref py py-mod docutils literal notranslate"><span class="pre">datetime</span></code></a></dt><dd><p>Object-oriented interface to dates and times with similar functionality to the
  673. <a class="reference internal" href="time.html#module-time" title="time: Time access and conversions."><code class="xref py py-mod docutils literal notranslate"><span class="pre">time</span></code></a> module.</p>
  674. </dd>
  675. <dt>Module <a class="reference internal" href="time.html#module-time" title="time: Time access and conversions."><code class="xref py py-mod docutils literal notranslate"><span class="pre">time</span></code></a></dt><dd><p>Low-level time related functions.</p>
  676. </dd>
  677. </dl>
  678. </div>
  679. <section id="command-line-usage">
  680. <span id="calendar-cli"></span><h2>Command-Line Usage<a class="headerlink" href="#command-line-usage" title="Link to this heading">¶</a></h2>
  681. <div class="versionadded">
  682. <p><span class="versionmodified added">New in version 2.5.</span></p>
  683. </div>
  684. <p>The <a class="reference internal" href="#module-calendar" title="calendar: Functions for working with calendars, including some emulation of the Unix cal program."><code class="xref py py-mod docutils literal notranslate"><span class="pre">calendar</span></code></a> module can be executed as a script from the command line
  685. to interactively print a calendar.</p>
  686. <div class="highlight-shell notranslate"><div class="highlight"><pre><span></span>python<span class="w"> </span>-m<span class="w"> </span>calendar<span class="w"> </span><span class="o">[</span>-h<span class="o">]</span><span class="w"> </span><span class="o">[</span>-L<span class="w"> </span>LOCALE<span class="o">]</span><span class="w"> </span><span class="o">[</span>-e<span class="w"> </span>ENCODING<span class="o">]</span><span class="w"> </span><span class="o">[</span>-t<span class="w"> </span><span class="o">{</span>text,html<span class="o">}]</span>
  687. <span class="w"> </span><span class="o">[</span>-w<span class="w"> </span>WIDTH<span class="o">]</span><span class="w"> </span><span class="o">[</span>-l<span class="w"> </span>LINES<span class="o">]</span><span class="w"> </span><span class="o">[</span>-s<span class="w"> </span>SPACING<span class="o">]</span><span class="w"> </span><span class="o">[</span>-m<span class="w"> </span>MONTHS<span class="o">]</span><span class="w"> </span><span class="o">[</span>-c<span class="w"> </span>CSS<span class="o">]</span>
  688. <span class="w"> </span><span class="o">[</span>year<span class="o">]</span><span class="w"> </span><span class="o">[</span>month<span class="o">]</span>
  689. </pre></div>
  690. </div>
  691. <p>For example, to print a calendar for the year 2000:</p>
  692. <div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="gp">$ </span>python<span class="w"> </span>-m<span class="w"> </span>calendar<span class="w"> </span><span class="m">2000</span>
  693. <span class="go"> 2000</span>
  694. <span class="go"> January February March</span>
  695. <span class="go">Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su</span>
  696. <span class="go"> 1 2 1 2 3 4 5 6 1 2 3 4 5</span>
  697. <span class="go"> 3 4 5 6 7 8 9 7 8 9 10 11 12 13 6 7 8 9 10 11 12</span>
  698. <span class="go">10 11 12 13 14 15 16 14 15 16 17 18 19 20 13 14 15 16 17 18 19</span>
  699. <span class="go">17 18 19 20 21 22 23 21 22 23 24 25 26 27 20 21 22 23 24 25 26</span>
  700. <span class="go">24 25 26 27 28 29 30 28 29 27 28 29 30 31</span>
  701. <span class="go">31</span>
  702. <span class="go"> April May June</span>
  703. <span class="go">Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su</span>
  704. <span class="go"> 1 2 1 2 3 4 5 6 7 1 2 3 4</span>
  705. <span class="go"> 3 4 5 6 7 8 9 8 9 10 11 12 13 14 5 6 7 8 9 10 11</span>
  706. <span class="go">10 11 12 13 14 15 16 15 16 17 18 19 20 21 12 13 14 15 16 17 18</span>
  707. <span class="go">17 18 19 20 21 22 23 22 23 24 25 26 27 28 19 20 21 22 23 24 25</span>
  708. <span class="go">24 25 26 27 28 29 30 29 30 31 26 27 28 29 30</span>
  709. <span class="go"> July August September</span>
  710. <span class="go">Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su</span>
  711. <span class="go"> 1 2 1 2 3 4 5 6 1 2 3</span>
  712. <span class="go"> 3 4 5 6 7 8 9 7 8 9 10 11 12 13 4 5 6 7 8 9 10</span>
  713. <span class="go">10 11 12 13 14 15 16 14 15 16 17 18 19 20 11 12 13 14 15 16 17</span>
  714. <span class="go">17 18 19 20 21 22 23 21 22 23 24 25 26 27 18 19 20 21 22 23 24</span>
  715. <span class="go">24 25 26 27 28 29 30 28 29 30 31 25 26 27 28 29 30</span>
  716. <span class="go">31</span>
  717. <span class="go"> October November December</span>
  718. <span class="go">Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su</span>
  719. <span class="go"> 1 1 2 3 4 5 1 2 3</span>
  720. <span class="go"> 2 3 4 5 6 7 8 6 7 8 9 10 11 12 4 5 6 7 8 9 10</span>
  721. <span class="go"> 9 10 11 12 13 14 15 13 14 15 16 17 18 19 11 12 13 14 15 16 17</span>
  722. <span class="go">16 17 18 19 20 21 22 20 21 22 23 24 25 26 18 19 20 21 22 23 24</span>
  723. <span class="go">23 24 25 26 27 28 29 27 28 29 30 25 26 27 28 29 30 31</span>
  724. <span class="go">30 31</span>
  725. </pre></div>
  726. </div>
  727. <p>The following options are accepted:</p>
  728. <dl class="std option">
  729. <dt class="sig sig-object std" id="cmdoption-calendar-help">
  730. <span id="cmdoption-calendar-h"></span><span class="sig-name descname"><span class="pre">--help</span></span><span class="sig-prename descclassname"></span><span class="sig-prename descclassname"><span class="pre">,</span> </span><span class="sig-name descname"><span class="pre">-h</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-calendar-help" title="Link to this definition">¶</a></dt>
  731. <dd><p>Show the help message and exit.</p>
  732. </dd></dl>
  733. <dl class="std option">
  734. <dt class="sig sig-object std" id="cmdoption-calendar-locale">
  735. <span id="cmdoption-calendar-L"></span><span class="sig-name descname"><span class="pre">--locale</span></span><span class="sig-prename descclassname"> <span class="pre">LOCALE</span></span><span class="sig-prename descclassname"><span class="pre">,</span> </span><span class="sig-name descname"><span class="pre">-L</span></span><span class="sig-prename descclassname"> <span class="pre">LOCALE</span></span><a class="headerlink" href="#cmdoption-calendar-locale" title="Link to this definition">¶</a></dt>
  736. <dd><p>The locale to use for month and weekday names.
  737. Defaults to English.</p>
  738. </dd></dl>
  739. <dl class="std option">
  740. <dt class="sig sig-object std" id="cmdoption-calendar-encoding">
  741. <span id="cmdoption-calendar-e"></span><span class="sig-name descname"><span class="pre">--encoding</span></span><span class="sig-prename descclassname"> <span class="pre">ENCODING</span></span><span class="sig-prename descclassname"><span class="pre">,</span> </span><span class="sig-name descname"><span class="pre">-e</span></span><span class="sig-prename descclassname"> <span class="pre">ENCODING</span></span><a class="headerlink" href="#cmdoption-calendar-encoding" title="Link to this definition">¶</a></dt>
  742. <dd><p>The encoding to use for output.
  743. <a class="reference internal" href="#cmdoption-calendar-encoding"><code class="xref std std-option docutils literal notranslate"><span class="pre">--encoding</span></code></a> is required if <a class="reference internal" href="#cmdoption-calendar-locale"><code class="xref std std-option docutils literal notranslate"><span class="pre">--locale</span></code></a> is set.</p>
  744. </dd></dl>
  745. <dl class="std option">
  746. <dt class="sig sig-object std" id="cmdoption-calendar-type">
  747. <span id="cmdoption-calendar-t"></span><span class="sig-name descname"><span class="pre">--type</span></span><span class="sig-prename descclassname"> <span class="pre">{text,html}</span></span><span class="sig-prename descclassname"><span class="pre">,</span> </span><span class="sig-name descname"><span class="pre">-t</span></span><span class="sig-prename descclassname"> <span class="pre">{text,html}</span></span><a class="headerlink" href="#cmdoption-calendar-type" title="Link to this definition">¶</a></dt>
  748. <dd><p>Print the calendar to the terminal as text,
  749. or as an HTML document.</p>
  750. </dd></dl>
  751. <dl class="std option">
  752. <dt class="sig sig-object std" id="cmdoption-calendar-arg-year">
  753. <span class="sig-name descname"><span class="pre">year</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-calendar-arg-year" title="Link to this definition">¶</a></dt>
  754. <dd><p>The year to print the calendar for.
  755. Must be a number between 1 and 9999.
  756. Defaults to the current year.</p>
  757. </dd></dl>
  758. <dl class="std option">
  759. <dt class="sig sig-object std" id="cmdoption-calendar-arg-month">
  760. <span class="sig-name descname"><span class="pre">month</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-calendar-arg-month" title="Link to this definition">¶</a></dt>
  761. <dd><p>The month of the specified <a class="reference internal" href="#cmdoption-calendar-arg-year"><code class="xref std std-option docutils literal notranslate"><span class="pre">year</span></code></a> to print the calendar for.
  762. Must be a number between 1 and 12,
  763. and may only be used in text mode.
  764. Defaults to printing a calendar for the full year.</p>
  765. </dd></dl>
  766. <p><em>Text-mode options:</em></p>
  767. <dl class="std option">
  768. <dt class="sig sig-object std" id="cmdoption-calendar-width">
  769. <span id="cmdoption-calendar-w"></span><span class="sig-name descname"><span class="pre">--width</span></span><span class="sig-prename descclassname"> <span class="pre">WIDTH</span></span><span class="sig-prename descclassname"><span class="pre">,</span> </span><span class="sig-name descname"><span class="pre">-w</span></span><span class="sig-prename descclassname"> <span class="pre">WIDTH</span></span><a class="headerlink" href="#cmdoption-calendar-width" title="Link to this definition">¶</a></dt>
  770. <dd><p>The width of the date column in terminal columns.
  771. The date is printed centred in the column.
  772. Any value lower than 2 is ignored.
  773. Defaults to 2.</p>
  774. </dd></dl>
  775. <dl class="std option">
  776. <dt class="sig sig-object std" id="cmdoption-calendar-lines">
  777. <span id="cmdoption-calendar-l"></span><span class="sig-name descname"><span class="pre">--lines</span></span><span class="sig-prename descclassname"> <span class="pre">LINES</span></span><span class="sig-prename descclassname"><span class="pre">,</span> </span><span class="sig-name descname"><span class="pre">-l</span></span><span class="sig-prename descclassname"> <span class="pre">LINES</span></span><a class="headerlink" href="#cmdoption-calendar-lines" title="Link to this definition">¶</a></dt>
  778. <dd><p>The number of lines for each week in terminal rows.
  779. The date is printed top-aligned.
  780. Any value lower than 1 is ignored.
  781. Defaults to 1.</p>
  782. </dd></dl>
  783. <dl class="std option">
  784. <dt class="sig sig-object std" id="cmdoption-calendar-spacing">
  785. <span id="cmdoption-calendar-s"></span><span class="sig-name descname"><span class="pre">--spacing</span></span><span class="sig-prename descclassname"> <span class="pre">SPACING</span></span><span class="sig-prename descclassname"><span class="pre">,</span> </span><span class="sig-name descname"><span class="pre">-s</span></span><span class="sig-prename descclassname"> <span class="pre">SPACING</span></span><a class="headerlink" href="#cmdoption-calendar-spacing" title="Link to this definition">¶</a></dt>
  786. <dd><p>The space between months in columns.
  787. Any value lower than 2 is ignored.
  788. Defaults to 6.</p>
  789. </dd></dl>
  790. <dl class="std option">
  791. <dt class="sig sig-object std" id="cmdoption-calendar-months">
  792. <span id="cmdoption-calendar-m"></span><span class="sig-name descname"><span class="pre">--months</span></span><span class="sig-prename descclassname"> <span class="pre">MONTHS</span></span><span class="sig-prename descclassname"><span class="pre">,</span> </span><span class="sig-name descname"><span class="pre">-m</span></span><span class="sig-prename descclassname"> <span class="pre">MONTHS</span></span><a class="headerlink" href="#cmdoption-calendar-months" title="Link to this definition">¶</a></dt>
  793. <dd><p>The number of months printed per row.
  794. Defaults to 3.</p>
  795. </dd></dl>
  796. <p><em>HTML-mode options:</em></p>
  797. <dl class="std option">
  798. <dt class="sig sig-object std" id="cmdoption-calendar-css">
  799. <span id="cmdoption-calendar-c"></span><span class="sig-name descname"><span class="pre">--css</span></span><span class="sig-prename descclassname"> <span class="pre">CSS</span></span><span class="sig-prename descclassname"><span class="pre">,</span> </span><span class="sig-name descname"><span class="pre">-c</span></span><span class="sig-prename descclassname"> <span class="pre">CSS</span></span><a class="headerlink" href="#cmdoption-calendar-css" title="Link to this definition">¶</a></dt>
  800. <dd><p>The path of a CSS stylesheet to use for the calendar.
  801. This must either be relative to the generated HTML,
  802. or an absolute HTTP or <code class="docutils literal notranslate"><span class="pre">file:///</span></code> URL.</p>
  803. </dd></dl>
  804. </section>
  805. </section>
  806. <div class="clearer"></div>
  807. </div>
  808. </div>
  809. </div>
  810. <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
  811. <div class="sphinxsidebarwrapper">
  812. <div>
  813. <h3><a href="../contents.html">Table of Contents</a></h3>
  814. <ul>
  815. <li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">calendar</span></code> — General calendar-related functions</a><ul>
  816. <li><a class="reference internal" href="#command-line-usage">Command-Line Usage</a></li>
  817. </ul>
  818. </li>
  819. </ul>
  820. </div>
  821. <div>
  822. <h4>Previous topic</h4>
  823. <p class="topless"><a href="zoneinfo.html"
  824. title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">zoneinfo</span></code> — IANA time zone support</a></p>
  825. </div>
  826. <div>
  827. <h4>Next topic</h4>
  828. <p class="topless"><a href="collections.html"
  829. title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">collections</span></code> — Container datatypes</a></p>
  830. </div>
  831. <div role="note" aria-label="source link">
  832. <h3>This Page</h3>
  833. <ul class="this-page-menu">
  834. <li><a href="../bugs.html">Report a Bug</a></li>
  835. <li>
  836. <a href="https://github.com/python/cpython/blob/main/Doc/library/calendar.rst"
  837. rel="nofollow">Show Source
  838. </a>
  839. </li>
  840. </ul>
  841. </div>
  842. </div>
  843. <div id="sidebarbutton" title="Collapse sidebar">
  844. <span>«</span>
  845. </div>
  846. </div>
  847. <div class="clearer"></div>
  848. </div>
  849. <div class="related" role="navigation" aria-label="related navigation">
  850. <h3>Navigation</h3>
  851. <ul>
  852. <li class="right" style="margin-right: 10px">
  853. <a href="../genindex.html" title="General Index"
  854. >index</a></li>
  855. <li class="right" >
  856. <a href="../py-modindex.html" title="Python Module Index"
  857. >modules</a> |</li>
  858. <li class="right" >
  859. <a href="collections.html" title="collections — Container datatypes"
  860. >next</a> |</li>
  861. <li class="right" >
  862. <a href="zoneinfo.html" title="zoneinfo — IANA time zone support"
  863. >previous</a> |</li>
  864. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  865. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  866. <li class="switchers">
  867. <div class="language_switcher_placeholder"></div>
  868. <div class="version_switcher_placeholder"></div>
  869. </li>
  870. <li>
  871. </li>
  872. <li id="cpython-language-and-version">
  873. <a href="../index.html">3.12.3 Documentation</a> &#187;
  874. </li>
  875. <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
  876. <li class="nav-item nav-item-2"><a href="datatypes.html" >Data Types</a> &#187;</li>
  877. <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">calendar</span></code> — General calendar-related functions</a></li>
  878. <li class="right">
  879. <div class="inline-search" role="search">
  880. <form class="inline-search" action="../search.html" method="get">
  881. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  882. <input type="submit" value="Go" />
  883. </form>
  884. </div>
  885. |
  886. </li>
  887. <li class="right">
  888. <label class="theme-selector-label">
  889. Theme
  890. <select class="theme-selector" oninput="activateTheme(this.value)">
  891. <option value="auto" selected>Auto</option>
  892. <option value="light">Light</option>
  893. <option value="dark">Dark</option>
  894. </select>
  895. </label> |</li>
  896. </ul>
  897. </div>
  898. <div class="footer">
  899. &copy;
  900. <a href="../copyright.html">
  901. Copyright
  902. </a>
  903. 2001-2024, Python Software Foundation.
  904. <br />
  905. This page is licensed under the Python Software Foundation License Version 2.
  906. <br />
  907. Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
  908. <br />
  909. See <a href="/license.html">History and License</a> for more information.<br />
  910. <br />
  911. The Python Software Foundation is a non-profit corporation.
  912. <a href="https://www.python.org/psf/donations/">Please donate.</a>
  913. <br />
  914. <br />
  915. Last updated on Apr 09, 2024 (13:47 UTC).
  916. <a href="/bugs.html">Found a bug</a>?
  917. <br />
  918. Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 7.2.6.
  919. </div>
  920. </body>
  921. </html>
上海开阖软件有限公司 沪ICP备12045867号-1