- over.core.misc.console now accepts globals as well as locals to offer a complete environment

- new over.core.file.count_lines
- over.core.types.ndict can now export keys with dashes in them same way over.core.app.Main does it (by translating them to underscores)
This commit is contained in:
Overwatch 2015-01-14 13:14:34 +01:00
parent 043ad86808
commit 402a05f86d
5 changed files with 32 additions and 4 deletions

View file

@ -85,3 +85,19 @@ def touch(fname, times=None):
with open(fname, 'a'):
os.utime(fname, times)
# --------------------------------------------------
def count_lines(filename):
'''
A reasonably fast and memory-lean line counter.
'''
lines = 0
buffer = bytearray(2048)
with open(filename, 'rb') as f:
while f.readinto(buffer):
lines += buffer.count(b'\n')
return lines