File opener and closener when managed via `with`.
Project description
Archiwith
Class that gives you the mini help to avoid to write open(file_path,'r')
or open(file_path,'w')
every time ypu want to work with some text file.
Installation
You can easily install archiwith
using pip:
pip install archiwith
or via git:
git clone https://github.com/niCodeLine/archiwith.git
or just copy-paste it into your code.
Usage
To use the mini helper simply import the class and call it stating the file path of the text file you want to open. Then use it with the with
method. Here's a simple example:
Reading
from archiwith import Archiwith
# Stating the file path
reader = Archiwith('path/to/your/file').abrir()
# Using the with method
with reader as file:
# Do something with the file
Another way and opening a binari:
# Stating the file path
reader = Archiwith('path/to/your/file')
# Reading as binari file
with reader.abrir(binari=True) as file:
# Do something with the file
If the file is text-readeable you can just:
# Stating the file path
reader = Archiwith('path/to/your/file')
text = reader.leer()
or shorter:
# Stating the file path
text = Archiwith('path/to/your/file').leer()
Writing
# Stating the file path
writer = Archiwith('path/to/your/file').escribir()
# Using the with method
with writer as file:
# Write the file
ObjetiFiles
This implementation speeds up file handling by allowing access to file names as attributes, eliminating the need to manually write them out one by one. For example, lets say your folder has a structure like this:
your_folder/
│
├── firstcode.py
├── another_folder/
├── outputs.txt
├── tests.txt
└── my programs.py
You can access to the names via:
from archiwith import ObjectiFiles
path = 'path/to/your_folder'
files = ObjectiFiles(path)
This will create the files
object with the valid files as attributes and nameing them with a f_file_name__ext
form. So:
>>> files.f_tests__txt
'tests.txt'
>>> files.f_my_programs__py
'my programs.py'
If you have suggestions enabled in your code editor (command I in VS Code), you will get the names when typing files.f
. The f
prefix comes from File and is to get a clearer view of what are the files in the autocomplete suggestions.
Features
That would be it.
Contributions
Contributions are welcome! If you have improvements or fixes, please send a pull request or open an issue in the GitHub repository.
License
This project is licensed under the MIT License. See the LICENSE
file for more details.
Contact
Nico Spok - nicospok@hotmail.com GitHub: niCodeLine
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
File details
Details for the file archiwith-1.2.tar.gz
.
File metadata
- Download URL: archiwith-1.2.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
671fc4205c0c4fc007301a8eb4c1f47cdbcc1a14596fed8e9ea21c389e5c0a0d
|
|
MD5 |
6d8bc0decca620d872941fe8ee86b8ba
|
|
BLAKE2b-256 |
4fd061cc462993f7f1cc09fc79bb19e0251789a0dd4ad207a4aa0b66446b47ed
|