Skip to main content

Handling files super easily

Project description

fhandleio

A simple library for easy file handling

Installation

  1. To install, type the command:
pip install fhandleio
  1. 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

from fhandleio 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fhandleio-1.0.1.tar.gz (4.4 kB view hashes)

Uploaded Source

Built Distribution

fhandleio-1.0.1-py3-none-any.whl (4.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page