Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DISCUSSION] Py3k simple #114

Closed
wants to merge 12 commits into from
2 changes: 1 addition & 1 deletion ocrolib/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ def unpickle_find_global(mname,cname):
if mname=="lstm.lstm":
from . import lstm
return getattr(lstm,cname)
if not mname in sys.modules.keys():
if not mname in sys.modules:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should have made this not in.

exec("import "+mname)
return getattr(sys.modules[mname],cname)

Expand Down
2 changes: 1 addition & 1 deletion ocrolib/extras/lru.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def wrapper(*args, **kwds):
# purge least frequently used cache entry
if len(cache) > maxsize:
for key, _ in nsmallest(maxsize // 10,
use_count.iteritems(),
iter(use_count.items()),
key=itemgetter(1)):
del cache[key], use_count[key]

Expand Down
4 changes: 2 additions & 2 deletions ocrolib/lattice.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def lastState(self):
def classes(self):
edges = chain.from_iterable(self.edges.values())
classes = set([e.cls for e in edges])
return sorted(list(classes))
return sorted(classes)

class Lattice2:
"""Like Lattice, but handles whitespace by multi-char classes"""
Expand Down Expand Up @@ -114,4 +114,4 @@ def lastState(self):
def classes(self):
edges = chain.from_iterable(self.edges.values())
classes = set([e.cls for e in edges])
return sorted(list(classes))
return sorted(classes)
2 changes: 1 addition & 1 deletion ocrolib/ngraphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def buildFromFiles(self,fnames,n):
def computePosteriors(self,counter):
"""Given a `counter` of all n-graphs, compute
(log) conditional probabilities."""
self.N = len(counter.items()[0][0])
self.N = len(list(counter.items())[0][0])
ngrams = defaultdict(list)
for k,v in counter.items():
ngrams[k[:-1]].append((k,v))
Expand Down
2 changes: 1 addition & 1 deletion ocrolib/toplevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def wrapper(*args,**kw):
global _trace1_depth
_trace1_depth += 1
print(" " * _trace1_depth, "ENTER", name, ":", end=' ')
for k,v in zip(argnames,args)+kw.items():
for k,v in zip(argnames,args)+list(kw.items()):
print("%s=%s" % (k, strc(v)), end=' ')
print()
result = f(*args,**kw)
Expand Down