samedi 21 avril 2018

Python Function running on a random date

#first and last day of every month

s_january, e_january =      ("1/1/2017"), ("1/31/2017")  
s_february, e_february =    ("2/1/2017"), ("2/28/2017")
s_march, e_march =          ("3/1/2017"), ("3/31/2017")
s_april, e_april =          ("4/1/2017"), ("4/30/2017")
s_may, e_may =              ("5/1/2017"), ("5/31/2017")
s_june, e_june =            ("6/1/2017"), ("6/30/2017")
s_july, e_july =            ("7/1/2017"), ("7/31/2017")
s_august, e_august =        ("8/1/2017"), ("8/31/2017")
s_September, e_September =  ("9/1/2017"), ("9/30/2017")
s_october, e_october =      ("10/1/2017"), ("10/31/2017")
s_november, e_november =    ("11/1/2017"), ("11/30/2017")
s_december, e_december =    ("12/1/2017"), ("12/31/2017")

def foo(s_date, e_date):
    does stuff


foo(s_january, e_january)
foo(s_february, e_february)
foo(s_march, e_march)
foo(s_april, e_april)
foo(s_may, e_may)
foo(s_june, e_june)
foo(s_july, e_july)
foo(s_august, e_august)
foo(s_september, e_september)
foo(s_october, e_october)
foo(s_november, e_november)
foo(s_december, e_december)

I have a function that on a random date does stuff, but I have to call the function for every month, if I put the range for year I don't get the result that I want.

Is there any better way to avoid running it 12 times?




Aucun commentaire:

Enregistrer un commentaire