Skip to main content

Managing the text files txt, csv and json

Project description

TextFiles v0.0.1

A convenient Python API for working with the text files CSV, JSON, TXT This is a shared project with Yael Ben Yair https://github.com/YaelBenYair

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

textfiles-0.0.2.tar.gz (11.6 kB view details)

Uploaded Source

Built Distribution

textfiles-0.0.2-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

Details for the file textfiles-0.0.2.tar.gz.

File metadata

  • Download URL: textfiles-0.0.2.tar.gz
  • Upload date:
  • Size: 11.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.0rc1

File hashes

Hashes for textfiles-0.0.2.tar.gz
Algorithm Hash digest
SHA256 7d29f87dad09c76cb71ee68e9f908a74cb518cf2ce8699fc898045ecbff0e93e
MD5 ee0fc24562addf4e07d53d8fd9c9bd9f
BLAKE2b-256 5eb88e83a0ed7ba0b0bdd7d8f6172059bad7bcfa2b5a1cbe03ab687c69971303

See more details on using hashes here.

File details

Details for the file textfiles-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: textfiles-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 12.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.0rc1

File hashes

Hashes for textfiles-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8633f1008d33a974fa30bf3e1a3b52976b192916a8802ae4e94a49d8f3722769
MD5 854ff939c6bd16862ab052bd2a70539c
BLAKE2b-256 f0b5dc973cfa18ea4b3c037620a1815073fb13eb2b61db1569ffdf54c3750e27

See more details on using hashes here.

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