Skip to main content

Utils to save your time on python coding

Project description


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'))

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


    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'))
    lines1:['hello', 'ezflines']
    lines2 = readlines(brother_path('cfg.txt'), False)
    lines2:['hello\n', 'ezflines\n']

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

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

def read_as_string():
    string = readstr(brother_path('cfg.txt'))

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__":

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for ezfiles, version 0.0.1
Filename, size File type Python version Upload date Hashes
Filename, size ezfiles-0.0.1-py3.7.egg (4.2 kB) File type Egg Python version 3.7 Upload date Hashes View
Filename, size ezfiles-0.0.1-py3-none-any.whl (2.9 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size ezfiles-0.0.1.tar.gz (2.8 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page