Skip to content

Commit

Permalink
16.2 using libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
epequeno committed Feb 15, 2013
1 parent 262d463 commit 49114f0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
2 changes: 1 addition & 1 deletion ch09/9.01.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ def words(word):
percent = (float(wordCount) / float(lineCount)) * 100.0
print "%0.4f%%" % percent

words(wordList)
words(wordList)
20 changes: 9 additions & 11 deletions ch16/16.02.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,22 @@

# Current Satus: Complete

import time
import datetime

class Time(object):
"""Time object based on datetime.datetime describes time in 24hr format"""
def __init__(self, year=2000, month=1, day=1, hour=12, minute=0, sec=0):
self.date = datetime.datetime(year, month, day, hour, minute, sec)

def time_to_int(self):
return int(self.date.strftime("%s"))

# 1 AM on Jan 1, 2001
t1 = Time(2001, 1, 1, 1)

# 12 AM on Jan 1, 2001
t2 = Time(2001, 1, 1, 0)

def mktime(self):
return time.mktime(self.date.timetuple())


t1 = Time(2013, 1, 3, 15)
t2 = Time(2013, 1, 3, 1)

def is_after(time1, time2):
return time1.time_to_int() > time2.time_to_int()
return time1.mktime() > time2.mktime()

print is_after(t2, t1)
print is_after(t1, t2)

0 comments on commit 49114f0

Please sign in to comment.