python - I'm unable to get date with a variable -


def get_next_monday(year, month, day):     date0 = datetime.date(year, month, day)     next_monday = date0 + datetime.timedelta(7 - date0.weekday() or 7)     return next_monday  date2 = datetime.datetime.now().strftime("%y, %m, %d") findnextweek = get_next_monday(date2) 

if replace (year, month, day) (date2) integer required. otherwise, different error

typeerror: get_next_monday() takes 3 arguments (1 given)

you have little problems in code. here's fix , explanation:

import datetime  def get_next_monday(year, month, day):      # if want accept str , int, must convert strings      date0 = datetime.date(int(year), int(month), int(day))     next_monday = date0 + datetime.timedelta(7 - date0.weekday() or 7)     return next_monday   # must convert date in list, because `get_next_monday` takes 3 arguments. initial_date = datetime.datetime.now().strftime("%y, %m, %d").split(',')  # must un-pack date findnextweek = get_next_monday(*initial_date)  print(findnextweek) 

note should calling get_next_monday get_next_monday(2016, 6, 10) or get_next_monday('2016', '6', '10').

there's no sense of creating datetime object, converting in string, list, , re-converting in datetime object.

anyways hope :)


Comments

Popular posts from this blog

AbotX : How do you create a parallel crawler that stays on and can be added to at run time from new requests -

testing - Detect whether test has failed within fixture -

android - Create single AAR file from multiple modules using Gradle -