Monday, May 25, 2009

Diving right into python.

This summer i am undertaking quite a big project, which, hopefully you will hear all about. A very small part of the project is to get the current day of the week. I decided to code it in python. After a few hours of self teaching i began coding. A bit of research on the net and many many failed attempts at syntax later:

#!/usr/bin/python
# Filename : date-to-day.py

import datetime
from datetime import date

now = datetime.datetime.now()
year = now.year
month = now.month
day = now.day
dayofweek = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saterday', 'Sunday']
daytoday = dayofweek[date.weekday(date(year,month,day))]
print daytoday


As i couldn't find a solution for this i thought i would post mine here. =]

Python is actually very good.

No comments:

Post a Comment