CorrectOCR.fileio module¶
-
class
CorrectOCR.fileio.FileIO[source]¶ Bases:
objectVarious file IO helper methods.
-
classmethod
ensure_new_file(path)[source]¶ Moves a possible existing file out of the way by adding a numeric counter before the extension.
- Parameters
path (
Path) – The path to check.
-
classmethod
ensure_directories(path)[source]¶ Ensures that the entire path exists.
- Parameters
path (
Path) – The path to check.
-
classmethod
save(data, path, backup=True)[source]¶ Saves data into a file. The extension determines the method of saving:
.pickle – uses
pickle..json – uses
json..csv – uses
csv.DictWriter(assumes data is list ofvars()-capable objects). The keys of the first object determines the header.
Any other extension will simply
write()the data to the file.- Parameters
data (
Any) – The data to save.path (
Path) – The path to save to.backup – Whether to move existing files out of the way via
ensure_new_file()
-
classmethod
load(path, default=None)[source]¶ Loads data from a file. The extension determines the method of saving:
.pickle – uses
pickle..json – uses
json..csv – uses
csv.DictReader.
Any other extension will simply
read()the data from the file.- Parameters
path (
Path) – The path to load from.default – If file doesn’t exist, return default instead.
- Returns
The data from the file, or the default.
-
classmethod