#--- Calendars --- #For some reason the compiler for this one fs up hard I think its because all these are calendar conflict eachother import calendar # create a plain text calendar c = calendar.TextCalendar(calendar.SUNDAY) #The sunday Represents first day #2013 year str = c.formatmonth(2013, 1, 0, 0) #1month which will spelled out in compiler print str #0,0i dont really know # create an HTML formatted calendar################################################################################ hc = calendar.HTMLCalendar(calendar.SUNDAY) This totally f up in example str = hc.formatmonth(2013, 1) print str # loop over the days of a month########################################################################################### # zeroes mean that the day of the week is in an overlapping month for i in c.itermonthdays(2013, 8): print i #i = loop #Starts with a list of days in which beginning days that dont belong to the monthwill have 0 #it will just list the numbers wont exactly loop # The Calendar module provides useful utilities for the given locale,########################################################### # such as the names of days and months in both full and abbreviated forms for name in calendar.month_name: print name for day in calendar.day_name: print day #i = loop #But in this case its name and day #Starts with a list of days in which beginning days that dont belong to the monthwill have 0 #it will just list the numbers wont exactly loop ############################################################################################################################ # Calculate days based on a rule: For example, consider # a team meeting on the first Friday of every month. # To figure out what days that would be for each month, # we can use this script: for m in range(1,13): #Range of months # returns an array of weeks that represent the month cal = calendar.monthcalendar(2013, m) #Amount weeks # The first Friday has to be within the first two weeks weekone = cal[0] #We are just interested in the friday weektwo = cal[1] if weekone[calendar.FRIDAY] != 0: meetday = weekone[calendar.FRIDAY] else: # if the first friday isn't in the first week, it must be in the second #This is a if / else statement meetday = weektwo[calendar.FRIDAY] #%10 spaces #%2 spaces print "%10s %2d" % (calendar.month_name[m], meetday) #Result is something like August 2
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question