944,048 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Unsolved
  • Views: 1596
  • Python RSS
Jan 17th, 2007
0

week from given year

Expand Post »
[code]
def WeekFinderFromYear(year):
""" will return all the week from selected year """
import datetime

WEEK = {'MONDAY':0,'TUESDAY':1,'WEDNESDAY':2,'THURSDAY':3,'FRIDAY':4,'SATURDAY':5,'SUNDAY':6}
MONTH = {'JANUARY':1,'FEBRUARY':2,'MARCH':3,'APRIL':4,'MAY':5,'JUNE':6,'JULY':7,'AUGUST':8,'SEPTEMBER':9,'OCTOBER':10,'NOVEMBER':11,'DECEMBER':12}

year=int(year)
month= MONTH['JANUARY']
day=WEEK['MONDAY']
dt = datetime.date(year,month,1)
dow_lst = []

while dt.weekday() != day:
dt = dt + datetime.timedelta(days=1)

lst_month = MONTH.values()
lst_month.sort()
for mont in lst_month:
while dt.month == mont:
dow_lst.append(dt)
dt = dt + datetime.timedelta(days=7)

#for each in dow_lst:
# print each
return dow_lst

year=raw_input("Enter the year:")
week_list = WeekFinderFromYear(year)
for each in week_list:
print each

[inlinecode]
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sharma_vivek82 is offline Offline
18 posts
since Mar 2006
Jan 17th, 2007
0

Re: week from given year

Code tags are particularly important with Python code since they preserve the indentations. Without the proper indentations Python code becomes hard to read and understand!

I will show the needed tags in reverse so they don't activate:
at the end of your code add this tag [/code]
at the start of your code add tag [code=Python]
Moderator
Reputation Points: 1333
Solved Threads: 1403
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: creating batch in python
Next Thread in Python Forum Timeline: notepad in wxPython





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC