For the beginning you could use print-debugging.
Just print the variables before this statement.
I try to explain the DAYTIMES a little bit
Just print the variables before this statement.
self._weekday = weekdays[weekdays.index(self._weekday)-6]Or put it in a try block and print in the excpetion block the variables.
I try to explain the DAYTIMES a little bit
In [10]: DAYTIMES Out[10]: {'winter': {'midnight': (0, 1), 'night': (20, 23), 'dawn': (5, 6), 'morning': (7, 11), 'noon': (12, 13), 'afternoon': (14, 17), 'dusk': (18, 19)}, 'spring': {'midnight': (0, 1), 'night': (20, 23), 'dawn': (5, 6), 'morning': (7, 11), 'noon': (12, 13), 'afternoon': (14, 17), 'dusk': (18, 19)}, 'summer': {'midnight': (0, 1), 'night': (20, 23), 'dawn': (5, 6), 'morning': (7, 11), 'noon': (12, 13), 'afternoon': (14, 17), 'dusk': (18, 19)}, 'autumn': {'midnight': (0, 1), 'night': (20, 23), 'dawn': (5, 6), 'morning': (7, 11), 'noon': (12, 13), 'afternoon': (14, 17), 'dusk': (18, 19)}} In [11]: DAYTIMES.keys() Out[11]: dict_keys(['winter', 'spring', 'summer', 'autumn']) In [12]: [d.keys() for d in DAYTIMES.values()] Out[12]: [dict_keys(['midnight', 'night', 'dawn', 'morning', 'noon', 'afternoon', 'dusk']), dict_keys(['midnight', 'night', 'dawn', 'morning', 'noon', 'afternoon', 'dusk']), dict_keys(['midnight', 'night', 'dawn', 'morning', 'noon', 'afternoon', 'dusk']), dict_keys(['midnight', 'night', 'dawn', 'morning', 'noon', 'afternoon', 'dusk'])] In [13]: month = 5 In [14]: SEASONS[month] --------------------------------------------------------------------------- KeyError Traceback (most recent call last) <ipython-input-14-251ea90b9689> in <module> ----> 1 SEASONS[month] KeyError: 5 In [15]: for season, months in SEASONS.items(): ...: # key, value ...: if month in months: ...: print(season) ...: # break out of the loop ...: # return is not possible on module level ...: break ...: # lath season is still there after ...: # leaving the block ...: spring In [16]: season Out[16]: 'spring' In [17]: hour = 6 In [18]: # now the overlapping range function In [19]: # @staticmethod ...: def overlapping_in_range(value, min_val, max_val): ...: if min_val < max_val: ...: return min_val <= value < max_val ...: elif min_val > max_val: ...: return value >= min_val or value < max_val ...: # if you use this in a class, you could put a ...: # @staticmethod on the top ...: # you have already your state attributes in your ...: # class ...: ...: ...: In [21]: DAYTIMES[season] Out[21]: {'midnight': (0, 1), 'night': (20, 23), 'dawn': (5, 6), 'morning': (7, 11), 'noon': (12, 13), 'afternoon': (14, 17), 'dusk': (18, 19)} In [22]: # ok same again, nested structures are sometimes anoying In [23]: for daytime, (start_hour, end_hour) in DAYTIMES[season].items(): ...: # the items methos returns the key, value ...: # daytime is the key, ...: # the tuple (start_hour, end_hour) ...: # consomes the value, which is a tuple (iterable) ...: # it's called tuple unpacking and is allowd in ...: # assigment on the left side and in for loops ...: # now accessing the variable hour ...: # and call it with the function overlapping ...: if overlapping_in_range(hour, start_hour, end_hour): ...: # if you have not used the tuple, ...: # (start_hour, end_hour) ...: # instead: ...: # for daytime, range_tuple in ... ...: break # remind normally we would return in a function ...: # daytime and start_hour, end_hour are still available ...: In [24]: daytime Out[24]: 'dusk' In [25]: start_hour Out[25]: 18 In [26]: end_hour Out[26]: 19 In [27]: foo, (bar, baz) = 1, (2 , 3) In [28]: foo, bar, baz Out[28]: (1, 2, 3) In [29]: # or better visible In [30]: (foo, (bar, baz)) = (1, (2, 3)) # I love Python In [31]: foo Out[31]: 1 In [32]: bar Out[32]: 2 In [33]: baz Out[33]: 3 In [34]: # the overlapping function works as follows ...: # ----- ...: # min_val == start_hour ...: # max_val == end_hour ...: # ...: # start_hour is inclusive ...: # end_hour is exclusive ...: # mathematically correct expressed: ...: # [start_hour, end_hour) ...: # you have to add the minutes to be able ...: # to get the right result for the maximum ...: # if the end_hour is 00:59 and the is ...: # 01:00, you can just add the minutes to the integer ...: # hour = hour + minute / 60 ...: # and when you want to do this also for seconds ...: # hour = hour + minute / 60 + second / 3600 ...: # no parenthesis needed, Python follows the rules of Math ...: # hour is after this operation a float, no longer an integer ...: # you can compare integers with floats and reversed ...: # but never compare of equality of floats, won't work.. ...: # ...: # now the details about the function overlapping ...: # ...: # first case, min value is less than max value ...: # ...: # min value is less than or equal hour ...: # max value is less then hour ...: # ---- ...: # second case, min value is bigger than max value ...: # ...: # current_hour is bigger or equal min_val ...: # or, (hour won't be bigger than 23) ...: # current_hour is less than max_val ...: #
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!