ezutils


Nameezutils JSON
Version 0.0.6 PyPI version JSON
download
home_pagehttps://github.com/caojianfeng/ezutils
SummaryUtils to save your time on python coding
upload_time2024-09-24 17:11:58
maintainerNone
docs_urlNone
authorJeffreyCao
requires_python>=3.6
licenseMIT Licence
keywords color file progress ezutils
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # ezutils
Utils to save your time on python coding

Life is short we use ezutils !

## 1. Installing
```bash
pip install ezutils
```

## 2. Using files

### 2.1 readlines:

readlines(filename: str, strip_newline: bool = True) 

#### 2.1.1 params:
```txt
filename: the filename tobe read

strip_newline: strip the last space/newline


```
#### 2.1.2 return lines readed from file

#### 2.1.3 Example:

```python
    lines = readlines(brother_path('cfg.txt'))
    print(lines)
```


### 2.2 writelines:

writelines(lines: List, filename, append_newline: bool = True) 

#### 2.2.1 params:
```txt
lines: lines tobe written
filename: file tobe written
append_newline: add a newline to each line writtend
```
#### 2.2.2 return None

Example:

```python
    lines = ['hello', 'ezflines']
    writelines(lines, brother_path('cfg.txt'))
```

### 2.3 readstr:

readstr(filename: str) -> str

#### 2.3.1 params:
```txt
filename: file tobe read
```
#### 2.3.2 return None

### 2.4 readjson:

readjson(filename: str) -> dict

#### 2.4.1 params:
```txt
filename: file tobe read
```
#### 2.4.2 return dict from json parse


## 2.5 DEMO

example/demo_files.py
```python

#!/usr/bin/env python3
# -*- coding:utf-8 -*-

import os
from ezutils.files import readlines, writelines, readstr, readjson, list_by_ext


def brother_path(filename): return os.path.join(
    os.path.dirname(__file__), filename)


def read_as_lines():
    lines1 = readlines(brother_path('cfg.txt'))
    print(f"lines1:{lines1}")
    '''
    lines1:['hello', 'ezflines']
    '''
    lines2 = readlines(brother_path('cfg.txt'), False)
    print(f"lines2:{lines2}")
    '''
    lines2:['hello\n', 'ezflines\n']
    '''


def write_as_lines():
    lines = ['hello', 'ezflines']
    writelines(lines, brother_path('cfg.txt'))
    '''
    cfg.txt:
    hello
    ezflines

    '''
    writelines(lines, brother_path('cfg_oneline.txt'), False)
    '''
    cfg_oneline.txt:
    helloezflines
    '''


def read_as_string():
    string = readstr(brother_path('cfg.txt'))
    print(f"read_as_string:\n{string}")


def read_as_json():
    json_obj = readjson(brother_path('cfg.json'))
    print(f"read_as_json: type = {type(json_obj)}")
    images = json_obj["images"]
    for image in images:
        print(f"read_as_json: image = {image}")


def find_pys():
    files = list_by_ext('.', 'py')
    index = 0
    width = len(f"{len(files)}")
    for file in files:
        print(f"[{index:0{width}}] {file}")
        index += 1


if __name__ == "__main__":
    write_as_lines()
    read_as_lines()
    read_as_string()
    read_as_json()
    find_pys()

```
## 3 Using progress

### 3.1 print_progress

print_progress(msg, current, max, max_width=60)

### Demo

example/demo_files.py

```python

#!/usr/bin/env python3
#demo_progress.py

import time

from ezutils.progress import print_progress

if __name__ == '__main__':
    max = 100
    for i in range(max + 1):
        print_progress("MSG:ABC(%d)" % i, i, max)
        time.sleep(0.01)
```
## TODO:

### pillow utils
add roundrect for pillow
see and ANTIALIAS  [circle_corner](https://www.pyget.cn/p/185266)

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/caojianfeng/ezutils",
    "name": "ezutils",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": "color, file, progress, ezutils",
    "author": "JeffreyCao",
    "author_email": "jeffreycao1024@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/6f/4d/dd40dfdfaa7b4de4baff8534e834cb3b05c89368802dad0c7bd9a4581efd/ezutils-0.0.6.tar.gz",
    "platform": "any",
    "description": "# ezutils\nUtils to save your time on python coding\n\nLife is short we use ezutils !\n\n## 1. Installing\n```bash\npip install ezutils\n```\n\n## 2. Using files\n\n### 2.1 readlines:\n\nreadlines(filename: str, strip_newline: bool = True) \n\n#### 2.1.1 params:\n```txt\nfilename: the filename tobe read\n\nstrip_newline: strip the last space/newline\n\n\n```\n#### 2.1.2 return lines readed from file\n\n#### 2.1.3 Example:\n\n```python\n    lines = readlines(brother_path('cfg.txt'))\n    print(lines)\n```\n\n\n### 2.2 writelines:\n\nwritelines(lines: List, filename, append_newline: bool = True) \n\n#### 2.2.1 params:\n```txt\nlines: lines tobe written\nfilename: file tobe written\nappend_newline: add a newline to each line writtend\n```\n#### 2.2.2 return None\n\nExample:\n\n```python\n    lines = ['hello', 'ezflines']\n    writelines(lines, brother_path('cfg.txt'))\n```\n\n### 2.3 readstr:\n\nreadstr(filename: str) -> str\n\n#### 2.3.1 params:\n```txt\nfilename: file tobe read\n```\n#### 2.3.2 return None\n\n### 2.4 readjson:\n\nreadjson(filename: str) -> dict\n\n#### 2.4.1 params:\n```txt\nfilename: file tobe read\n```\n#### 2.4.2 return dict from json parse\n\n\n## 2.5 DEMO\n\nexample/demo_files.py\n```python\n\n#!/usr/bin/env python3\n# -*- coding:utf-8 -*-\n\nimport os\nfrom ezutils.files import readlines, writelines, readstr, readjson, list_by_ext\n\n\ndef brother_path(filename): return os.path.join(\n    os.path.dirname(__file__), filename)\n\n\ndef read_as_lines():\n    lines1 = readlines(brother_path('cfg.txt'))\n    print(f\"lines1:{lines1}\")\n    '''\n    lines1:['hello', 'ezflines']\n    '''\n    lines2 = readlines(brother_path('cfg.txt'), False)\n    print(f\"lines2:{lines2}\")\n    '''\n    lines2:['hello\\n', 'ezflines\\n']\n    '''\n\n\ndef write_as_lines():\n    lines = ['hello', 'ezflines']\n    writelines(lines, brother_path('cfg.txt'))\n    '''\n    cfg.txt:\n    hello\n    ezflines\n\n    '''\n    writelines(lines, brother_path('cfg_oneline.txt'), False)\n    '''\n    cfg_oneline.txt:\n    helloezflines\n    '''\n\n\ndef read_as_string():\n    string = readstr(brother_path('cfg.txt'))\n    print(f\"read_as_string:\\n{string}\")\n\n\ndef read_as_json():\n    json_obj = readjson(brother_path('cfg.json'))\n    print(f\"read_as_json: type = {type(json_obj)}\")\n    images = json_obj[\"images\"]\n    for image in images:\n        print(f\"read_as_json: image = {image}\")\n\n\ndef find_pys():\n    files = list_by_ext('.', 'py')\n    index = 0\n    width = len(f\"{len(files)}\")\n    for file in files:\n        print(f\"[{index:0{width}}] {file}\")\n        index += 1\n\n\nif __name__ == \"__main__\":\n    write_as_lines()\n    read_as_lines()\n    read_as_string()\n    read_as_json()\n    find_pys()\n\n```\n## 3 Using progress\n\n### 3.1 print_progress\n\nprint_progress(msg, current, max, max_width=60)\n\n### Demo\n\nexample/demo_files.py\n\n```python\n\n#!/usr/bin/env python3\n#demo_progress.py\n\nimport time\n\nfrom ezutils.progress import print_progress\n\nif __name__ == '__main__':\n    max = 100\n    for i in range(max + 1):\n        print_progress(\"MSG:ABC(%d)\" % i, i, max)\n        time.sleep(0.01)\n```\n## TODO:\n\n### pillow utils\nadd roundrect for pillow\nsee and ANTIALIAS  [circle_corner](https://www.pyget.cn/p/185266)\n",
    "bugtrack_url": null,
    "license": "MIT Licence",
    "summary": "Utils to save your time on python coding",
    "version": "0.0.6",
    "project_urls": {
        "Homepage": "https://github.com/caojianfeng/ezutils"
    },
    "split_keywords": [
        "color",
        " file",
        " progress",
        " ezutils"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6f4ddd40dfdfaa7b4de4baff8534e834cb3b05c89368802dad0c7bd9a4581efd",
                "md5": "ff08d42e26d3a0a827d38ab0ac9a074b",
                "sha256": "7fef078be3ed61ef22fede9796144ce46860338e90418148a3ae0d9f985d4bae"
            },
            "downloads": -1,
            "filename": "ezutils-0.0.6.tar.gz",
            "has_sig": false,
            "md5_digest": "ff08d42e26d3a0a827d38ab0ac9a074b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 4645,
            "upload_time": "2024-09-24T17:11:58",
            "upload_time_iso_8601": "2024-09-24T17:11:58.614488Z",
            "url": "https://files.pythonhosted.org/packages/6f/4d/dd40dfdfaa7b4de4baff8534e834cb3b05c89368802dad0c7bd9a4581efd/ezutils-0.0.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-24 17:11:58",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "caojianfeng",
    "github_project": "ezutils",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "ezutils"
}
        
Elapsed time: 0.45851s