3. ###############################
# Calendar printing functions #
###############################
# Revision 2: uses funtions from built-in time module
# Import functions and variables from time module
from time import gmtime, localtime, mktime, asctime, ctime
# Exception raised for bad input (with string parameter for details)
error = 'calendar.error'
# Note when comparing these calendars to the ones printed by cal(1):
# My calendars have Monday as the first day of the week, and Sunday as
# the last! (I believe this is the European convention.)
1.5
"""Calendar printing functions
Note when comparing these calendars to the ones printed by cal(1): By
default, these calendars have Monday as the first day of the week, and
Sunday as the last (the European convention). Use setfirstweekday() to
set the first day of the week (0=Monday, 6=Sunday)."""
import sys
import datetime
from enum import IntEnum, global_enum
import locale as _locale
from itertools import repeat
import warnings
3.13 alpha 0
ドキュメンテーション
しっかりしてる(昔から)
コーディングスタイルは
ずいぶん違う
4. # Number of days per month (except for February in leap years)
mdays = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
1.5
# Number of days per month (except for February in leap years)
mdays = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
3.13 alpha 0
20年以上変わらない部分がある
5. # Constants for months referenced later
January = 1
February = 2
1.5
def __getattr__(name):
if name in ('January', 'February'):
warnings.warn(f"The '{name}' attribute is deprecated, use
'{name.upper()}' instead",
DeprecationWarning, stacklevel=2)
if name == 'January':
return 1
else:
return 2
raise AttributeError(f"module '{__name__}' has no attribute '{name}'")
3.13 alpha 0
モジュールレベルの定数的変数
廃止予定なので,名前を参照すると
Exceptionが出るようになっている
6. # Constants for months
@global_enum
class Month(IntEnum):
JANUARY = 1
FEBRUARY = 2
MARCH = 3
APRIL = 4
MAY = 5
JUNE = 6
JULY = 7
AUGUST = 8
SEPTEMBER = 9
OCTOBER = 10
NOVEMBER = 11
DECEMBER = 12
3.13 alpha 0
enumを使って12ヶ月分の定数が
新規に定義されている