Managing the text files txt, csv and json
Project description
TextFiles v0.0.4
A convenient Python API for working with the text files CSV, JSON, TXT
The library allows handling csv, txt and json files easily from within Python.
Installation
pip install textfiles
How to use:
Import TextFile: Once you install the library you can import the TextFile class into your Python code. To do this, simply add the following line to your code:
from textfiles.file_factory import TextFile
Use TextFile: You can now use the TextFile class to create instances of CsvFile, TxtFile, and JsonFile classes. The factory has two methods:
make_file_instance: This method creates an instance of the file class for an existing text file.
make_file: This method creates a new file and a corresponding Python instance of it.
To create an instance of a CsvFile, TxtFile, or JsonFile class, simply call the appropriate static method and pass in the necessary parameters. The factory will then return an instance of the appropriate class.
Examples: Here are some examples of how to use TextFile:
To create an instance of an existing file:
file = TextFile.make_file_instance('path/to/file.csv', 'csv', has_header=True, delimiter=',')
file = TextFile.make_file_instance('path/to/file.txt', 'txt')
file = TextFile.make_file_instance('path/to/file.json', 'json')
To create a new file:
file = TextFile.make_file('csv', 'path/to/file.csv', ['Header1', 'Header2'])
file = TextFile.make_file('txt', 'path/to/file.txt')
file = TextFile.make_file('json', 'path/to/file.json')
Note - When creating a CSV file, it is mandatory to pass a header.
Main functions:
self.get_content()
self.search()
self.count()
examples:
CsvFile.update_cell()
my_csv = CsvFile('/path/to/my/csv/file.csv')
my_csv.update_cell(column=3, row=2, value='New content')
JsonFile.search()
with open ("example.json", "w") as f:
json.dump(f, {"State": "New York", "cities": ["New York", "Albeny", "New Paltz"]})
my_json = JsonFile('/path/to/my/json/file.json')
new = my_json.search("new")
print(new)
output:
[{'State': 'New York'}, {'cities': [{'index[0]': 'New York'}, {'index[2]': 'New Paltz'}]}]
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
Built Distribution
File details
Details for the file textfiles-0.0.4.tar.gz
.
File metadata
- Download URL: textfiles-0.0.4.tar.gz
- Upload date:
- Size: 11.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.0rc1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3d0ca62154144ac5e807cd044b5ef0361584c046be683257a05c67b09c97098c |
|
MD5 | d92e88845cb5b8a9aeb186658e2e9657 |
|
BLAKE2b-256 | a2b9a35ea8c8fdd603b79c077bfddfe2489e3bf93b1f457416e4bb3cf8e674ac |
File details
Details for the file textfiles-0.0.4-py3-none-any.whl
.
File metadata
- Download URL: textfiles-0.0.4-py3-none-any.whl
- Upload date:
- Size: 11.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.0rc1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 603e2c91ef83cf0338b9733acad950ffe6338bf24e1349e2ffea750b046a15b2 |
|
MD5 | 9a5f76af6ad60f69eedf69fb498594e1 |
|
BLAKE2b-256 | c4ec51f65dcf0783eb271b70255e47ab29c7a123a7b3b9665c62fd2db83628d3 |