Skip to main content

Managing the text files txt, csv and json

Project description

TextFiles v0.0.7

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('csv', 'path/to/file.csv', has_header=True, delimiter=',')
file = TextFile.make_file_instance('txt', 'path/to/file.txt')
file = TextFile.make_file_instance('json', 'path/to/file.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.7.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for textfiles-0.0.7.tar.gz
Algorithm Hash digest
SHA256 a549699a24c53b526cbced2be6bfd567d7198d301698f054a998069d75526369
MD5 9a473c8e80074d5ca7593bde0feef309
BLAKE2b-256 268af9df237934480395b3ce49fb27968bde67de9759ed854a5f093e508f7a41

See more details on using hashes here.

File details

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

File metadata

  • Download URL: textfiles-0.0.7-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.0

File hashes

Hashes for textfiles-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 1b58bff4b6945e5cfee07cc58d05153554a63454ec82434055bf2524de545b4d
MD5 15472318026c4edcde36beee9843d1e0
BLAKE2b-256 3c5ca4cc8ab340c8f2f9f3391afc2ad5300faabf3f5d8fb7823bc3338630df09

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