当前位置: 首页>>代码示例>>Python>>正文


Python Calendar.get_month方法代码示例

本文整理汇总了Python中calendar.Calendar.get_month方法的典型用法代码示例。如果您正苦于以下问题:Python Calendar.get_month方法的具体用法?Python Calendar.get_month怎么用?Python Calendar.get_month使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在calendar.Calendar的用法示例。


在下文中一共展示了Calendar.get_month方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Handler

# 需要导入模块: from calendar import Calendar [as 别名]
# 或者: from calendar.Calendar import get_month [as 别名]
class Handler():
    """
    Handler Class
    """

    def __init__(self):
        self.calendar = Calendar()
        self.all_teams = []
        self.all_matches = []

    def list_calendar(self):
        """
        List all days in chosen month
        """
        while True:
            print("\n#### Calendar ####\n")
            print(self.calendar)

            try:
                choice = int(input("Choose month (0 to exit): "))
                break
            except ValueError:
                print("That's not an integer!")
                input("\nPress enter to choose again.")

        if choice == 0:
            print("\nExits back to main menu")
        else:
            month_holder = self.calendar.get_month(choice)
            print("\n#### " + month_holder.name + " ####\n")
            for day in month_holder.days_in_month:
                print(day)

    def book_day(self, the_match):
        """
        Book a day in the month
        """
        while True:
            try:
                mon = int(input("Enter month (1-12): "))
                day = int(input("Enter day (1-30/31): "))
                break
            except ValueError:
                print("\nNot an integer.")
                input("\nPress enter to choose again.")
        if not self.calendar.get_month(mon).get_day(day).booked:
            self.calendar.get_month(mon).get_day(day).book(the_match)
            print("\nMatch booked " + str(day) + "/" + str(mon) + "\n" + str(the_match))
        else:
            print("\nDate occupied. Choose another.")


    def create_team(self):
        """
        Create new team
        """
        self.list_teams()
        while True:
            try:
                t_name = input("\nTeam name: ")
                break
            except ValueError:
                print("\nThat was not an alternative. Try again.")

        self.all_teams.append(Team(t_name))


        print("\nTeam", t_name, "created.")


    def list_teams(self):
        """
        List all teams
        """
        counter = 1
        print("\n#### Teams ####\n")
        for team in self.all_teams:
            print(str(counter) + ": " + str(team))
            counter += 1

    def create_match(self):
        """
        Creates a match on a special date
        """

        new_sport = input("Type of sport? ")

        self.list_teams()

        while True:
            try:
                team1 = int(input("Choose first team: "))
                team2 = int(input("Choose second team: "))
                break
            except ValueError:
                print("Not an int. Try again.")

        new_match = Match(new_sport, (self.all_teams[team1-1], self.all_teams[team2-1]))

        self.book_day(new_match)
#.........这里部分代码省略.........
开发者ID:dbwebb-se,项目名称:oopython,代码行数:103,代码来源:handler.py


注:本文中的calendar.Calendar.get_month方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。