Kalenderwochen erzeugen mit Python

Basierend auf einem Kommentar zu http://code.activestate.com/recipes/521915-start-date-and-end-date-of-given-week/ hier ein kurzer Code-Schnipsel, der die Anfangs- und Endtage aller Kalenderwochen in 2014 ausspuckt.

from datetime import date, timedelta
 
def get_week_days(year, week):
    d = date(year,1,1)
    if(d.weekday()>3):
        d = d+timedelta(7-d.weekday())
    else:
        d = d - timedelta(d.weekday())
    dlt = timedelta(days = (week-1)*7)
    return d + dlt,  d + dlt + timedelta(days=6)
 
for x in range(1, 54):
	a,b = get_week_days(2014,x);
	print ("\\subsection{" + a.strftime('%d.%m.%Y') + " -- " +  b.strftime('%d.%m.%Y') + "}\n\n\n");

Uwe

Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined. Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.

More Posts - Website