Fixed a couple of Windows-only issues related to writing to the intermediate file

This commit is contained in:
Crista Lopes
2013-10-25 16:50:10 -07:00
parent 089239d939
commit f784f3c9a2

View File

@@ -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('') # data[6] is word,NNNN from the word_freqs file, and then just the word
data.append(0) # data[7] is frequency data.append(0) # data[7] is frequency
word_freqs = touchopen('word_freqs', 'r+') word_freqs = touchopen('word_freqs', 'rb+')
f = open(sys.argv[1]) f = open(sys.argv[1])
while True: while True:
data[1] = [f.readline()] data[1] = [f.readline()]
@@ -78,9 +78,8 @@ while True:
break break
if not data[4]: 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)) word_freqs.writelines("%20s,%04d\n" % (data[5], 1))
if data[5] == 'i, n':
print "Got it " + str(data[1])
else: else:
word_freqs.seek(-26, 1) word_freqs.seek(-26, 1)
word_freqs.writelines("%20s,%04d\n" % (data[5], data[7])) word_freqs.writelines("%20s,%04d\n" % (data[5], data[7]))