| | |
week from given year
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Mar 2006
Posts: 18
Reputation:
Solved Threads: 0
[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]
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]
Best wishes,
Vivek Sharma
Zope/Python Developer
Vivek Sharma
Zope/Python Developer
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]
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]
May 'the Google' be with you!
![]() |
Similar Threads
- CraZy SALe! 50% OFF First Year for cPanel Reseller/Shared! Quality Hosting Folks! << (Web Hosting Deals)
- get week list of an year (Python)
- Sale: *50% Off*! Superb Value. Reliable. Great Features. 30 Day Money Back Guarantee! (Web Hosting Deals)
- $5 Hosting 3.5gb/40gbs!! 99.9% Uptime, 30 Day Money Back, Live Telephone/Chat Support (Web Hosting Deals)
- Calendar Creator (C)
- Do you use announcements on your site? (Social Media and Online Communities)
- Can't remove ColdFusion Trojan (Viruses, Spyware and other Nasties)
- Computer Architecture (Computer Science)
- Slooow computer... (Windows 95 / 98 / Me)
Other Threads in the Python Forum
- Previous Thread: creating batch in python
- Next Thread: notepad in wxPython
Views: 1152 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for Python
advanced assignment beginner bluetooth chmod cmd code convert count csv data decimals dictionary dynamic dynamically enter examples excel external file float format frange ftp function gnu gui heads hints homework import input jaunty java leftmouse line linux list lists loan loop module mouse multiple newb number numbers output parsing path pointer port prime program programming projects push py2exe pygame pyglet pyopengl pyqt python random raw_input recursion recursive scrolledtext slicenotation software ssh stderr string strings table tennis terminal text thread threading time tkinter tlapse tooltip tuple tutorial ubuntu unicode unix urllib urllib2 variable variables ventrilo web webservice windows wx.wizard wxpython xlib






