Modernize Python 2 code to get ready for Python 3

This commit is contained in:
cclauss
2018-03-21 21:41:35 +01:00
parent d521abd5d7
commit 1fa9eb3c2b
42 changed files with 169 additions and 112 deletions

View File

@@ -1,4 +1,5 @@
#!/usr/bin/env python
from __future__ import print_function
import sys, operator, string, os, threading, re
from util import getch, cls, get_input
from time import sleep
@@ -38,7 +39,7 @@ class FreqObserver(threading.Thread):
def refresh_screen(data):
# clear screen
cls()
print data
print(data)
sys.stdout.flush()
data_str = ""
@@ -57,7 +58,7 @@ class WordsCounter:
for line in f:
yield [w for w in re.findall('[a-z]{2,}', line.lower()) if w not in stopwords]
words = non_stop_words().next()
words = next(non_stop_words())
lock.acquire()
for w in words:
self.freqs[w] = 1 if w not in self.freqs else self.freqs[w]+1
@@ -66,8 +67,8 @@ class WordsCounter:
#
# The controller
#
print "Press space bar to fetch words from the file one by one"
print "Press ESC to switch to automatic mode"
print("Press space bar to fetch words from the file one by one")
print("Press ESC to switch to automatic mode")
model = WordsCounter()
view = FreqObserver(model.freqs)
with open(sys.argv[1]) as f: