2017-08-23 162 views
0

我正在嘗試打印出一些給定的月份和年份的日曆的代碼。 我的代碼如下所示:TypeError:int()參數必須是一個字符串,類似字節的對象或數字,而不是'NoneType'

#!/usr/bin/python3 
"""import calender""" 

import calendar 
import datetime 

""" begin function """ 


def get_the_first_day_of_the_week(month, year): 
    day_of_week = datetime.date(year, month, 1).weekday() 
    return 


def print_out_calender(months, years): 
    this_month = int(months) 
    this_year = int(years) 
    new = get_the_first_day_of_the_week(this_month, this_year) 
    new = int(new) 
    calendar.setfirstweekday(new) 
    calendar.monthcalendar(this_month, this_year) 
    return 


print_out_calender(12, 2017) 

我希望它打印出最新的矩陣,但我得到這樣的錯誤: 回溯(最近通話最後一個):

File "./practice12.py", line 25, in <module> 
    print_out_calender(12, 2017) 
    File "./practice12.py", line 19, in print_out_calender 
    new = int(new) 
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType' 

我新到python和編碼,所以有人可以告訴我爲什麼?

+1

您是不是指'get_the_first_day_of_the_week'內的'return day_of_week'? –

回答

2
new = get_the_first_day_of_the_week(this_month, this_year) 

分配的get_the_first_day_of_the_week()new返回值。

但是,get_the_first_day_of_the_week()什麼都不返回,即None

改變功能返回的東西(大概day_of_the_week),它應該工作。

0

這是因爲newNone的代碼。 int不能採用無類型參數。

0

返回DAY_OF_WEEK從get_the_first_day_of_the_week

0

您在get_the_first_day_of_the_week函數返回無。返回day_of_week或使day_of_week成爲全局變量。

相關問題