Skip to main content

Managing the text files txt, csv and json

Project description

TextFiles v0.0.5

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

textfiles-0.0.5.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

textfiles-0.0.5-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

Hashes for textfiles-0.0.5.tar.gz
Algorithm Hash digest
SHA256 8974e840154ba56bef438b5b5e9abb3bb81c17fe4acae93af1f52f5d2613f111
MD5 0f8cba26311d7fa40fb62fa0f0860704
BLAKE2b-256 d666f66d796c618bec4f59ac6865b7410563ac2bf65186f0a4db6228d0dedb51

See more details on using hashes here.

File details

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

File metadata

  • Download URL: textfiles-0.0.5-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

Hashes for textfiles-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 0d30dfa7f132ce26cfec49f84bf0abab76bf5dceba707eacd4701a92370c1f5b
MD5 f2dc89d6f9c8b889f373ac1181cbcf01
BLAKE2b-256 3837439b5d1b6251973ae22151a60c428a10c4a81db3825da22aeedfdbcfecfd

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