textfiles


Nametextfiles JSON
Version 0.0.6 PyPI version JSON
download
home_page
SummaryManaging the text files txt, csv and json
upload_time2023-05-04 16:49:23
maintainer
docs_urlNone
authorYael Ben Yair, Hemed Tov
requires_python
license
keywords python text file csv json txt
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# TextFiles v0.0.6
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
```terminal
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:

```python
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:

```python
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:

```python
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:
```python
    self.get_content()
    self.search()
    self.count()
```

### examples:

#### CsvFile.update_cell()
```python
    my_csv = CsvFile('/path/to/my/csv/file.csv')
    my_csv.update_cell(column=3, row=2, value='New content')
```

#### JsonFile.search()
```python
    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:
```python
[{'State': 'New York'}, {'cities': [{'index[0]': 'New York'}, {'index[2]': 'New Paltz'}]}]
```



            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "textfiles",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "python,text,file,csv,json,txt",
    "author": "Yael Ben Yair, Hemed Tov",
    "author_email": "<yaelmadmon1011@gmail.com>, <hemedbz@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/87/b3/b76e23e6c28a7956b05562af3a5ad7ccb28d44da77c6a442b527c3c6375f/textfiles-0.0.6.tar.gz",
    "platform": null,
    "description": "\n# TextFiles v0.0.6\nA convenient Python API for working with the text files CSV, JSON, TXT\n\nThe library allows handling csv, txt and json files easily from within Python.\n\n## Installation\n```terminal\npip install textfiles\n```\n\n## How to use:\n\nImport 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:\n\n```python\nfrom textfiles.file_factory import TextFile\n```\n\nUse TextFile: You can now use the TextFile class to create instances of CsvFile, TxtFile, and JsonFile classes. The factory has two methods:\n\nmake_file_instance: This method creates an instance of the file class for an existing text file.\n\nmake_file: This method creates a new file and a corresponding Python instance of it.\n\nTo 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.\n\nExamples: Here are some examples of how to use TextFile:\n\nTo create an instance of an existing file:\n\n```python\nfile = TextFile.make_file_instance('path/to/file.csv', 'csv', has_header=True, delimiter=',')\nfile = TextFile.make_file_instance('path/to/file.txt', 'txt')\nfile = TextFile.make_file_instance('path/to/file.json', 'json')\n```\n\nTo create a new file:\n\n```python\nfile = TextFile.make_file('csv', 'path/to/file.csv', ['Header1', 'Header2'])\nfile = TextFile.make_file('txt', 'path/to/file.txt')\nfile = TextFile.make_file('json', 'path/to/file.json')\n```\nNote - When creating a CSV file, it is mandatory to pass a header.\n\n### Main functions:\n```python\n    self.get_content()\n    self.search()\n    self.count()\n```\n\n### examples:\n\n#### CsvFile.update_cell()\n```python\n    my_csv = CsvFile('/path/to/my/csv/file.csv')\n    my_csv.update_cell(column=3, row=2, value='New content')\n```\n\n#### JsonFile.search()\n```python\n    with open (\"example.json\", \"w\") as f:\n        json.dump(f, {\"State\": \"New York\", \"cities\": [\"New York\", \"Albeny\", \"New Paltz\"]})\n\n\n    my_json = JsonFile('/path/to/my/json/file.json')\n    new = my_json.search(\"new\")\n    print(new)\n```\n\noutput:\n```python\n[{'State': 'New York'}, {'cities': [{'index[0]': 'New York'}, {'index[2]': 'New Paltz'}]}]\n```\n\n\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Managing the text files txt, csv and json",
    "version": "0.0.6",
    "project_urls": null,
    "split_keywords": [
        "python",
        "text",
        "file",
        "csv",
        "json",
        "txt"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a21ee7d312c3b8f5783db7a6f037c186cbaebe96d7a32f6a498a5bdb3a31454a",
                "md5": "f8710637fcded0855751ad44392dd970",
                "sha256": "71d76a719c945867f11cba39452efc66d5c8a7054ff5b71aeec4c387e9a15c05"
            },
            "downloads": -1,
            "filename": "textfiles-0.0.6-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f8710637fcded0855751ad44392dd970",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 12028,
            "upload_time": "2023-05-04T16:49:22",
            "upload_time_iso_8601": "2023-05-04T16:49:22.119664Z",
            "url": "https://files.pythonhosted.org/packages/a2/1e/e7d312c3b8f5783db7a6f037c186cbaebe96d7a32f6a498a5bdb3a31454a/textfiles-0.0.6-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "87b3b76e23e6c28a7956b05562af3a5ad7ccb28d44da77c6a442b527c3c6375f",
                "md5": "e4dc6f207894035309f57ed81f50568a",
                "sha256": "495c12fb92fc28624e05fdcc810a75f6a7760c1cd8eb5cb555184721eef47c12"
            },
            "downloads": -1,
            "filename": "textfiles-0.0.6.tar.gz",
            "has_sig": false,
            "md5_digest": "e4dc6f207894035309f57ed81f50568a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 10877,
            "upload_time": "2023-05-04T16:49:23",
            "upload_time_iso_8601": "2023-05-04T16:49:23.726438Z",
            "url": "https://files.pythonhosted.org/packages/87/b3/b76e23e6c28a7956b05562af3a5ad7ccb28d44da77c6a442b527c3c6375f/textfiles-0.0.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-05-04 16:49:23",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "textfiles"
}
        
Elapsed time: 0.07089s