Fnord

Random bits from a random nerd

Python Continues to Impress

I was browsing the Python 2.6 docs and saw the ‘datetime’ library. On a lark, I rewrote my old C-coded ’days’ app as Python:

1
2
3
4
5
6
7
8
9
10
11
12
13
14

    #!/usr/bin/env python
    # Rewrite of days-old calculator using Python. Gotta love this language!
    # pfh 2/12/09

    import datetime

    bd = datetime.date(year=1968,month=2,day=2)
    today = datetime.date.today()

    tdiff = today - bd

    print("\nToday is %s and you are %s days old.\n" \
    % (today.strftime("%A, %B %d %Y"), tdiff.days))

Took me all of ten minutes, and the code is shorter, easy to tweak and such. Damn, I’m liking Python.