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 details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

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

Uploaded Python 3

File details

Details for the file fhandleio-1.0.1.tar.gz.

File metadata

  • Download URL: fhandleio-1.0.1.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for fhandleio-1.0.1.tar.gz
Algorithm Hash digest
SHA256 1b23fe88ccc6ddd146fd34db6116d673dc18c929d770b56727643f53e343d231
MD5 46a5e53c869d0cbc3eae5a155834a5e0
BLAKE2b-256 b0e1534fc3b59841c38f80e61eb357a5d54aec10858e0b9f9f8a1ff5298706af

See more details on using hashes here.

File details

Details for the file fhandleio-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: fhandleio-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for fhandleio-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1156754424ba362000f749a13bb695159b8bf9f7cdd3816f0f9f23e39f046068
MD5 9a9201299bc56c25cb425ccb80b192ea
BLAKE2b-256 d07e4b6f93c4622d1609932da7bbccf7ab31d6e07a7fa94bd4466f51baf7e7da

See more details on using hashes here.

Supported by

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