Skip to content

Commit

Permalink
test reading 1M ngrams.
Browse files Browse the repository at this point in the history
  • Loading branch information
anderscui committed Feb 24, 2016
1 parent 772763a commit 0786f41
Show file tree
Hide file tree
Showing 11 changed files with 300,504 additions and 646,076 deletions.
45 changes: 30 additions & 15 deletions common/io.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import os
import datetime
import zipfile


def write_obj(file_name, obj):
with open(file_name, 'w') as f:
Expand All @@ -9,31 +13,41 @@ def write_str(file_name, s):
f.write(s)


def write_line(f, s):
if isinstance(s, basestring):
f.write(s)
else:
f.write(str(s))
f.write('\n')


def write_lines(file_name, lines):
with open(file_name, 'w') as f:
f.writelines(lines)


def read_all(file_name):
with open(file_name) as f:
def append_line(file_path, line):
with open(file_path, "a") as f:
f.write(line)
f.write('\n')


def read_all(file_path):
with open(file_path) as f:
return f.read()


def read_lines(file_name):
with open(file_name) as f:
def read_all_lines(file_path):
with open(file_path) as f:
return f.readlines()


import os
import datetime
def read_lines(file_path, n=10):
with open(file_path) as f:
i = 0
for line in f:
i += 1
if i <= n:
yield line
else:
break


def zip_extract_all(zip_file, target_dir):
with zipfile.ZipFile(zip_file, 'r') as z:
z.extractall(target_dir)


def modified_on(filename):
Expand All @@ -48,4 +62,5 @@ def accessed_on(filename):

def created_on(filename):
t = os.path.getctime(filename)
return datetime.datetime.fromtimestamp(t)
return datetime.datetime.fromtimestamp(t)

Binary file added common/tests/1M-total.zip
Binary file not shown.
Empty file added common/tests/__init__.py
Empty file.
Loading

0 comments on commit 0786f41

Please sign in to comment.