diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2020-07-11 00:50:00 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2020-07-11 00:50:00 +0200 |
| commit | 91e8fdb99e321496c54288fe5a3db6397c768c10 (patch) | |
| tree | 2bb82323466c7895eb705138e561278b02ce8ca2 /cli/app/utils/file_utils.py | |
| parent | 2001ddd7e2a8926ec97fdd4d5c73b2d4e5b293de (diff) | |
building basic site. need to include cursors, etc
Diffstat (limited to 'cli/app/utils/file_utils.py')
| -rw-r--r-- | cli/app/utils/file_utils.py | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/cli/app/utils/file_utils.py b/cli/app/utils/file_utils.py index 7f1f417..0e672fc 100644 --- a/cli/app/utils/file_utils.py +++ b/cli/app/utils/file_utils.py @@ -195,12 +195,14 @@ def load_yaml(fp_in): cfg = yaml.load(fp, Loader=yaml.Loader) return cfg -def load_text(fp_in): +def load_text(fp_in, split=True): """Load a text file into an array :param fp_in: (str) filepath """ with open(fp_in, 'rt') as fp: - lines = fp.read().rstrip('\n').split('\n') + lines = fp.read().rstrip('\n') + if split: + lines = lines.split('\n') return lines def load_line_lookup(fp_in): @@ -264,16 +266,16 @@ def write_pickle(data, fp_out, ensure_path=True): pickle.dump(data, fp) -def write_json(data, fp_out, minify=True, ensure_path=True, sort_keys=True, verbose=False): +def write_json(data, fp_out, minify=True, ensure_path=True, sort_keys=True, verbose=False, default=None): """ """ if ensure_path: mkdirs(fp_out) with open(fp_out, 'w') as fp: if minify: - json.dump(data, fp, separators=(',',':'), sort_keys=sort_keys) + json.dump(data, fp, separators=(',',':'), sort_keys=sort_keys, default=default) else: - json.dump(data, fp, indent=2, sort_keys=sort_keys) + json.dump(data, fp, indent=2, sort_keys=sort_keys, default=default) if verbose: log.info('Wrote JSON: {}'.format(fp_out)) |
