IO (input-output functions)
utilz.io
I/O Module
crawl(where='.', ignore_git=True, respect_gitignore=True, ignore=None)
Crawls a folder and returns a list of Path objects containing folders and files while respecting gitignore files if present an any additional ignore file names or patterns
Parameters:
Name | Type | Description | Default |
---|---|---|---|
where |
Union[str, Path]
|
location to glob in. Defaults to ".". |
'.'
|
ignore_git |
bool
|
ignore |
True
|
respect_gitignore |
bool
|
read and ignore all files and patterns in |
True
|
ignore |
Union[None, list, str]
|
additional files or patterns to ignore. Defaults to None. |
None
|
Returns:
Name | Type | Description |
---|---|---|
List |
List
|
description |
Source code in utilz/io.py
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
|
load(f, as_arr=False, as_str=False, verbose=False, glob='*', glob_sort=True, assert_notempty=True, loader_func=None, **kwargs)
A handy dandy all-in-one loading function. Simply pass a Path object to a file or directory and you'll back a python object or list of objects based on the file-extension:
.csv
:pd.Dataframe
.p/.pickle
: output ofpickle.load
.json
:str
ordict
.npy
:np.ndarray
.txt
:np.ndarray
,list[str]
(lines a file), orstr
(all file contents)- other file-extensions are attempted to be loaded like
.txt
files - if give a directory all files matching
glob
in that directory will be loaded
Parameters:
Name | Type | Description | Default |
---|---|---|---|
f |
Path/str
|
name or path object to load |
required |
as_arr |
bool
|
treat a .txt file as a numpy array; |
False
|
as_str |
bool
|
open txt/json as a single string instead of |
False
|
assert_notempty(bool, |
optional
|
make sure the output is not Falsey (e.g. empty |
required |
verbose |
bool
|
whether to print messages during load. Default False |
False
|
**kwargs |
keyword arguments to |
{}
|
|
glob |
string
|
globbing pattern if f is a directory. Defaults to all files |
'*'
|
glob_sort |
bool
|
sort the globa before loadin. Defaults to True |
True
|
assert_notempty |
bool
|
raise an error if the returned output is |
True
|
loader_func |
callable
|
a custom function to use for loading; Default None, uses file extension |
None
|
Returns:
Type | Description |
---|---|
Any
|
the loaded object or list of objects |
Source code in utilz/io.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
|