From f784f3c9a23a78332a48346c46304e5243db0b36 Mon Sep 17 00:00:00 2001 From: Crista Lopes Date: Fri, 25 Oct 2013 16:50:10 -0700 Subject: [PATCH] Fixed a couple of Windows-only issues related to writing to the intermediate file --- 01-good-old-times/tf-01.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/01-good-old-times/tf-01.py b/01-good-old-times/tf-01.py index c800542..5d5fdb2 100755 --- a/01-good-old-times/tf-01.py +++ b/01-good-old-times/tf-01.py @@ -41,7 +41,7 @@ data.append('') # data[5] is the word data.append('') # data[6] is word,NNNN from the word_freqs file, and then just the word data.append(0) # data[7] is frequency -word_freqs = touchopen('word_freqs', 'r+') +word_freqs = touchopen('word_freqs', 'rb+') f = open(sys.argv[1]) while True: data[1] = [f.readline()] @@ -78,9 +78,8 @@ while True: break if not data[4]: + word_freqs.seek(0, 1) # Not needed in Unix, needed in Windows word_freqs.writelines("%20s,%04d\n" % (data[5], 1)) - if data[5] == 'i, n': - print "Got it " + str(data[1]) else: word_freqs.seek(-26, 1) word_freqs.writelines("%20s,%04d\n" % (data[5], data[7]))