mirror of
https://github.com/python/cpython.git
synced 2025-12-04 08:34:25 +00:00
Make byext.py really work.
This commit is contained in:
parent
d2e44df07a
commit
7c77f753b4
1 changed files with 5 additions and 7 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
#! /usr/bin/env python
|
#! /usr/bin/env python3.0
|
||||||
|
|
||||||
"""Show file statistics by extension."""
|
"""Show file statistics by extension."""
|
||||||
|
|
||||||
|
|
@ -60,13 +60,13 @@ class Stats:
|
||||||
data = f.read()
|
data = f.read()
|
||||||
f.close()
|
f.close()
|
||||||
self.addstats(ext, "bytes", len(data))
|
self.addstats(ext, "bytes", len(data))
|
||||||
if '\0' in data:
|
if b'\0' in data:
|
||||||
self.addstats(ext, "binary", 1)
|
self.addstats(ext, "binary", 1)
|
||||||
return
|
return
|
||||||
if not data:
|
if not data:
|
||||||
self.addstats(ext, "empty", 1)
|
self.addstats(ext, "empty", 1)
|
||||||
#self.addstats(ext, "chars", len(data))
|
#self.addstats(ext, "chars", len(data))
|
||||||
lines = data.splitlines()
|
lines = str(data, "latin-1").splitlines()
|
||||||
self.addstats(ext, "lines", len(lines))
|
self.addstats(ext, "lines", len(lines))
|
||||||
del lines
|
del lines
|
||||||
words = data.split()
|
words = data.split()
|
||||||
|
|
@ -77,14 +77,12 @@ class Stats:
|
||||||
d[key] = d.get(key, 0) + n
|
d[key] = d.get(key, 0) + n
|
||||||
|
|
||||||
def report(self):
|
def report(self):
|
||||||
exts = self.stats.keys()
|
exts = sorted(self.stats)
|
||||||
exts.sort()
|
|
||||||
# Get the column keys
|
# Get the column keys
|
||||||
columns = {}
|
columns = {}
|
||||||
for ext in exts:
|
for ext in exts:
|
||||||
columns.update(self.stats[ext])
|
columns.update(self.stats[ext])
|
||||||
cols = columns.keys()
|
cols = sorted(columns)
|
||||||
cols.sort()
|
|
||||||
colwidth = {}
|
colwidth = {}
|
||||||
colwidth["ext"] = max([len(ext) for ext in exts])
|
colwidth["ext"] = max([len(ext) for ext in exts])
|
||||||
minwidth = 6
|
minwidth = 6
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue