如何在Python 3.6中以月历矩阵格式打印日历?

如何在Python 3.6中以月历矩阵格式打印日历?,python,calendar,datetime-format,Python,Calendar,Datetime Format,我已经用Python创建了印度国家日历函数,如下所示 import calendar import datetime 'Days in Tamil names. first day start from 0-Monday and 6- sunday. similar to ISO format' tamil_day = ('திங்கள்','செவ்வாய்','புதன்','வியாழன்','வெள்ளி','சனி','ஞாயிறு') 'months in Tamil names

我已经用Python创建了印度国家日历函数,如下所示

import calendar
import datetime

'Days in Tamil names. first day start from 0-Monday and 6- sunday. similar to ISO format'
tamil_day = ('திங்கள்','செவ்வாய்','புதன்','வியாழன்','வெள்ளி','சனி','ஞாயிறு')

'months in Tamil names. first month start from 0-Chithirai and 11-panguni. similar to ISO format'
tamil_months = ('சித்திரை','வைகாசி','ஆணி','ஆடி','ஆவணி','புரட்டாசி','ஐப்பசி','கார்த்திகை','மார்கழி','தை','மாசி','பங்குனி')
'''reference date for Indian Saka Era
Saka Era 1876 is equal to 1954-55AD or Saka 1875-76 is equal to 1954
March 22,1954 is Chithirai 1,1876 Saka as Indian new year
'''
saka_year_AD_reference = datetime.date(1954,3,22)
saka_year_reference = 1876
saka_year_offset = 78
tamil_first_day_reference = calendar.firstweekday()
tamil_first_month_reference = tamil_months[0]
'''
number of days in each tamil month
normal year- chithirai-30days;
leap year- chithirai-31 days
'''
days_in_month_normal_year = (30,31,31,31,31,31,30,30,30,30,30,30)
days_in_month_leap_year = (31,31,31,31,31,31,30,30,30,30,30,30)

'Enter the year to print the calendar'
year = 1876

'find the year is leap year or not'
def tamil_leap_year(year):
    leap=year+saka_year_offset
    return calendar.isleap(leap)

'find the first day in given year'
def tamil_first_day_in_year(year):
    offset_compensation = year+saka_year_offset

    if tamil_leap_year(year):
        return calendar.weekday(offset_compensation,3,21)
    else:
        return calendar.weekday(offset_compensation,3,22)

def print_year(year):
    if tamil_leap_year(year)!=True:
        day_count = tamil_first_day_in_year(year)

        for i in range(12):
            print('\n','{:*^16}'.format(tamil_months[i]),'  \n','_______________')

            for i in range(1,(1+days_in_month_normal_year[i])):
                print('{:<2}'.format(i),"|",'{: <2}'.format(tamil_day[day_count]),'\n',end='')
                day_count = day_count+1

                if i<=31:
                    if day_count==7:
                        day_count = 0
                    continue
                else:
                    break
    else:
        day_count = tamil_first_day_in_year(year)

        for i in range(12):
            print(tamil_months[i],'|')

            for i in range(1,(1+days_in_month_leap_year[i])):
                print(i,"|",tamil_day[day_count])
                day_count = day_count+1

                if i<=31:
                    if day_count==7:
                        day_count = 0
                    continue
                else:
                    break

print(print_year(year))

不幸的是,我是Python的初学者,我不知道如何进行循环来创建frame-the-month表。有人能帮我解决这个问题吗?

首先将整数转换成字符串,然后添加位置函数作为center()。问题解决了。
谢谢

泰米尔历和公历有何不同?是否要打印脚本字符而不是日期?如果是这样的话,你希望得到什么样的填充?换句话说,我不清楚您想要什么输出。您好,印度日历一个月只有30天和31天,不像公历,从28天到31天不等。例如,我想打印的不是一月சித்திரை 而不是周一,周二我想打印திங்கள்,செவ்வாய் 等我的问题是打印周天数(即1、2、3等,最多30天)。我无法为每个月设置行和列的框架。
      January                   February                   March
 Mo Tu We Th Fr Sa Su      Mo Tu We Th Fr Sa Su      Mo Tu We Th Fr Sa Su
 1  2  3  4  5  6  7                1  2  3  4                1  2  3  4
 8  9 10 11 12 13 14       5  6  7  8  9 10 11       5  6  7  8  9 10 11
 15 16 17 18 19 20 21      12 13 14 15 16 17 18      12 13 14 15 16 17 18
 22 23 24 25 26 27 28      19 20 21 22 23 24 25      19 20 21 22 23 24 25
 29 30 31                  26 27 28                  26 27 28 29 30 31