0

I am still very new to python. Please excuse any basic mistakes. I've been reading around and experimenting, but I haven't been able to get this to work. The main function in my script prints out all the dates in one year. I want to pass each date value into the next function (fun_Phase1) until all dates in the year have been processed. Any help would be greatly appreciated.

import requests
import json 
import calendar

def fun_Phase1(_DATE):
    # Run additional code here
    print "You are in function Phase1 and the date is " + _DATE

def fun_Main():
    cal = calendar.Calendar()
    for year in range(2015,2016):
        for month in range(1,13):
            monthdays = [d for d in cal.itermonthdays(year,month) if d != 0]
            for day in monthdays:
                str_year = str(year)
                if month < 10:
                    str_month = "0" + str(month)
                    # print(str_month)
                else:
                    str_month = str(month)
                    # print(str_month)
                if day < 10:
                    str_day = "0" + str(day)
                    # print(str_day)
                else:
                    str_day = str(day)
                    # print(str_day)
                _DATE = str_year + str_month  + str_day
                # print(_DATE)
                fun_Phase1(_DATE)

# Execute the code
fun_Main()

Thanks in advance.

2
  • 5
    what isn't working about your code? Commented Oct 1, 2017 at 6:50
  • if you are running this with python3, you just need to change print("You are in function Phase1 and the date is " + _DATE) Commented Oct 1, 2017 at 6:54

1 Answer 1

1

I tried running your code but as @PRMoureu Said, You just need to change this

def fun_Phase1(_DATE):
    # Run additional code here
    print "You are in function Phase1 and the date is " + _DATE

to this

def fun_Phase1(_DATE):
    # Run additional code here
    print ("You are in function Phase1 and the date is " + _DATE)
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks very much for your help @PRMoureu and Tabaene Haque. After you confirmed that the logic was correct, I dug back into the errors that I was receiving and it turned out to be an indentation error. As mentioned before, I am still getting used to all the nuances of this language. After I fixed that up, as well as the print statement. It started working. Thanks again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.