Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7c77f75

Browse files
committed
Make byext.py really work.
1 parent d2e44df commit 7c77f75

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

Tools/scripts/byext.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#! /usr/bin/env python
1+
#! /usr/bin/env python3.0
22

33
"""Show file statistics by extension."""
44

@@ -60,13 +60,13 @@ def statfile(self, filename):
6060
data = f.read()
6161
f.close()
6262
self.addstats(ext, "bytes", len(data))
63-
if '\0' in data:
63+
if b'\0' in data:
6464
self.addstats(ext, "binary", 1)
6565
return
6666
if not data:
6767
self.addstats(ext, "empty", 1)
6868
#self.addstats(ext, "chars", len(data))
69-
lines = data.splitlines()
69+
lines = str(data, "latin-1").splitlines()
7070
self.addstats(ext, "lines", len(lines))
7171
del lines
7272
words = data.split()
@@ -77,14 +77,12 @@ def addstats(self, ext, key, n):
7777
d[key] = d.get(key, 0) + n
7878

7979
def report(self):
80-
exts = self.stats.keys()
81-
exts.sort()
80+
exts = sorted(self.stats)
8281
# Get the column keys
8382
columns = {}
8483
for ext in exts:
8584
columns.update(self.stats[ext])
86-
cols = columns.keys()
87-
cols.sort()
85+
cols = sorted(columns)
8886
colwidth = {}
8987
colwidth["ext"] = max([len(ext) for ext in exts])
9088
minwidth = 6

0 commit comments

Comments
 (0)