filehandlers is a library for working with files.
The name of the package on PyPI is
See this guide for how to install packages.
See the subpages for more information.
filehandlers is built on a relatively simple model.
A file is represented with an instance of
The actual file will not be changed or even inspected when creating an instance of
Now, say you want to change that file... that is where the
filehandlers.FileManipulator class comes in. You need to pass the
AbstractFile instance when creating a
FileManipulator because otherwise the manipulator can't do it's job.
The manipulator includes code for a number of common functions that could be replicated with other code, but the goal of creating this model/API is to simplify it!
Here is a quick example that shows how to use filehandlers to write to a file:
# load in filehandlers from filehandlers import FileManipulator, AbstractFile # define the file my_cool_file = AbstractFile("log.txt") # create FileManipulator my_cool_files_changer = FileManipulator(my_cool_file) # write data to file 5 times for i in range(5): my_cool_files_changer.wrap_file().write("Message #" + i + ": " + debug_message)
and that is it!
You can see the full API documentation here.
The source can be found on GitHub.