-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
103 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
Help on module chainz.utils in chainz: | ||
|
||
NAME | ||
chainz.utils - A set of utility functions for chainz. | ||
|
||
FILE | ||
/Users/jag/dev/chainz/chainz/utils.py | ||
|
||
DESCRIPTION | ||
These help with common tasks like reading a file, searching a directory, etc. | ||
|
||
FUNCTIONS | ||
counter(callback) | ||
Will count the items that pass by, returning the count to the callback. | ||
|
||
>>> def log(ct): | ||
>>> print('Count %d' % ct) | ||
>>> Chain(xrange(4)).counter(log) >>> .filter(lambda x: x % 2 == 0).counter(log) >>> .sink() | ||
Count 4 | ||
Count 2 | ||
|
||
read_csv_dict_file(filepath, dialect=None) | ||
Iterates over a csv file, yielding each line as a dict. | ||
|
||
This uses csv.DictReader, so the file should be in a form appropriate to | ||
that. The dialect argument is supplied to the csv reader. | ||
|
||
read_csv_file(filepath, dialect=None) | ||
Iterates over a csv file, yielding each line as a tuple. | ||
|
||
The dialect argument is supplied to the csv reader. | ||
|
||
read_file_lines(filepath) | ||
Iterates over a file, line by line. | ||
|
||
This generator will yield each line in turn, without the linebreak. | ||
|
||
read_jsonl_file(filepath) | ||
Iterates over a jsonl file, yielding the JSON objects. | ||
|
||
walk_files(root_dir) | ||
Iterates under all the files under root_dir, yielding their filepath. | ||
|
||
walk_leaf_dirs(root_dir) | ||
Yield the paths of the leaf directories under root_dir. | ||
|
||
Leaf directories are those dirs that don't have any subdirectories. | ||
|
||
write_json_lines_to_filepath(filepath, append=False) | ||
A transform that writes the incoming objects as JSON objects, one per | ||
line, to the filepath. | ||
|
||
Use like chain.transform(transform_write_json_lines_to_filepath(the_filepath)) | ||
If append == True, append to the file instead of overwriting it. | ||
|
||
write_lines_to_filepath(filepath, append=False) | ||
A transform that writes the incoming objects, one per line, to | ||
the filepath. | ||
|
||
Use like chain.transform(transform_write_lines_to_filepath(the_filepath)) | ||
If append == True, append to the file instead of overwriting it. | ||
|
||
|