- 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:
parent
043ad86808
commit
402a05f86d
5 changed files with 32 additions and 4 deletions
16
core/file.py
16
core/file.py
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue