haxerl
haxerl

Reputation: 111

TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'

i am trying to make a code that print out calendar with some given months and years. My code look like this:

#!/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)

i expect it to print out matrix of date but i got an error like this: Traceback (most recent call last):

  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'

i am new to python and coding so can somebody tell me why?

Upvotes: 0

Views: 5026

Answers (4)

Will_of_fire
Will_of_fire

Reputation: 1189

You are returning None in get_the_first_day_of_the_week function. Either return day_of_week or make day_of_week a global variable.

Upvotes: 0

NoOne
NoOne

Reputation: 1

Return day_of_week from get_the_first_day_of_the_week

Upvotes: 0

Zinki
Zinki

Reputation: 446

new = get_the_first_day_of_the_week(this_month, this_year)

assigns the return value of get_the_first_day_of_the_week() to new.

However, get_the_first_day_of_the_week() returns nothing, i.e. None.

Change the function to return something (presumably day_of_the_week) and it should work.

Upvotes: 3

Max
Max

Reputation: 1363

That's because new is None in the code. int cannot take None type arguments.

Upvotes: 0

Related Questions