Handling files super easily
Project description
fhandleio
A simple library for easy file handling
Installation
- To install, type the command:
pip install fhandleio
- And you are done!
Basics
You are able to read, write, append, and create new files. These are the four basics for file handling. Saving and loading data will be explained in a bit
READING
import fhandleio
data = fhandleio.read("filename") # Takes the entire file
data = fhandleio.readb("filename") # Reads via bytes
data = fhandleio.readl("filename", index) # Index where the line is read
data = fhandleio.readls("filename") # Takes all lines and puts in a list
WRITING
data = fhandleio.write("filename", message) # Overrides file and writes message
data = fhandleio.writeb("filename", data) # Writes in byte format
data = fhandleio.writels("filename", message) # Writes in lines
APPENDING
data = fhandleio.append("filename", message) # Adds to bottom of file
data = fhandleio.appendb("filename", data) # Append bytes
CREATING
data = fhandleio.create("filename") # If file exists, creates error
And a bonus one for here is to check if a file exists
if fhandleio.check_file("filename"):
print("File exists!")
Saving & Loading Data
You also have a major ability to save and load data in this library as well. The process is straightforward, and easy to follow. SAVING
fhandleio.save_data(filename=filename, data=data, override=False, hashing=True, mode="txt")
The function has five parameters:
- Filename - The Name of File (NO EXTENSIONS)
- Data - Data to Store (Usually dictionaries)
- Override - If it should Override Current Save File
- Hashing - If it should encrypt data first
- Mode - txt, py, json, pickle
LOADING
fhandleio.load_data(filename, hashed=False, mode="pickle")
The function has only three parameters:
- Filename - The Name of File (NO EXTENSIONS)
- Hashed - If the data was encrypted from save
- Mode - txt, py, json, pickle
Other Functions
There are some smaller functions you can also use with the library
CHUNK READ Read the file, but only the amount of bytes you have
data = fhandleio.chunk_read("yellow.txt", 64) # Reads 64 bytes of yellow.txt
FILE NO Returns integer file descriptor used for I/O requests by system
num = fhandleio.fileno("what.mp3")
GET SIZE Gets byte size for file
size = fhandleio.get_size("hi.txt")
IS EMPTY Check if contents of a file are empty
if fhandleio.is_empty("yo.txt"):
print("Empty file alert")
RAW Gets the raw object for a file
object = fhandleio.raw("some.txt")
SEEK AND TELL Give it a set of position to tell what is and continue the text from there. (Uses file seek and tell)
stuff = fhandleio.seek_and_tell("hey.txt", (2, 0))
The confusing part is (2, 0)
- The first is offset - position of where you want to start
- Second is from_where - 0 is beginning, 1 is current, 2 is end of file
TRUNCATING Setting the size of the file to a specific byte size
fhandleio.trunc("somefile.txt", 1024) # Sets size to 1024 bytes
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for fhandleio-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | af4cefc133e3cf038bc786d709834d8d0bb591fbd2d14cfc52acf998320451a9 |
|
MD5 | f6ff9306a4df367865fc1ff3b397eb05 |
|
BLAKE2b-256 | 045567168daf380a77edb4f4701c47fe5af3b80b27345e16f5333f5c826bceaf |