Skip to main content

ezfiles

Utils to save your time on python coding

Life is short we use ezutils !

1. Installing

pip install ezfiles

2. Using

2.1 readlines:

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

2.1.1 params:

filename: the filename tobe read

strip_newline: strip the last space/newline

2.1.2 return lines readed from file

2.1.3 Example:

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

2.2 writelines:

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

2.2.1 params:

lines: lines tobe written
filename: file tobe written
append_newline: add a newline to each line writtend

2.2.2 return None

Example:

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

2.3 readstr:

readstr(filename: str) -> str

2.3.1 params:

filename: file tobe read

2.3.2 return None

2.4 readjson:

readjson(filename: str) -> dict

2.4.1 params:

filename: file tobe read

2.4.2 return dict from json parse

3. Demo

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

import os
from ezfiles import readlines, writelines, readstr, readjson


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}")


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

Metadata

Release files for ezfiles 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ezfiles 0.0.1
File Size Uploaded Provenance Actions
ezfiles-0.0.1.tar.gz 2.8 kB Without provenance Details for ezfiles-0.0.1.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for ezfiles 0.0.1
File Interpreter ABI Platform Actions
ezfiles-0.0.1-py3.7.egg Legacy Egg format - - Details for ezfiles-0.0.1-py3.7.egg
ezfiles-0.0.1-py3-none-any.whl Python 3 none any Details for ezfiles-0.0.1-py3-none-any.whl

Total release size: 9.9 kB

Release files / ezfiles-0.0.1.tar.gz

Download URL ezfiles-0.0.1.tar.gz
Size 2.8 kB
Tags Source
SHA-256 checksum
How to use checksums
eaf1527a0f672c0dcf97c12cbd8a3bcca14d6bd6effb85283ef42eedbadc3592
BLAKE2b-256 checksum
How to use checksums
2da7753b1764933d7ee1ce9ce0fdb6d4be0d8939ae98af67d96fed7b9572f86b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.39.0 CPython/3.7.4

Release files / ezfiles-0.0.1-py3.7.egg

Download URL ezfiles-0.0.1-py3.7.egg
Size 4.2 kB
Tags Egg
SHA-256 checksum
How to use checksums
48fa682f798fa7ab155e8d0db20719fa172e84eeed1e0a31398886c7385826f8
BLAKE2b-256 checksum
How to use checksums
a7cc90454a820130c72b8e7e03e4e5d1ee95b2b30c65a44608e7636c7ee61cb4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.39.0 CPython/3.7.4

Release files / ezfiles-0.0.1-py3-none-any.whl

Download URL ezfiles-0.0.1-py3-none-any.whl
Size 2.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
98a3aa64c288c7ad004c8599b899be31392c70316e993756594d180d6fbeb659
BLAKE2b-256 checksum
How to use checksums
253ffac882f7ef8f355fd3ef8e8c7f9938d1777176b2d5f13494cd4345f44669
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.39.0 CPython/3.7.4

Security for ezfiles 0.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.1 This release

3 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page