Utils to save your time on python coding
Project description
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()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ezfiles-0.0.1.tar.gz.
File metadata
- Download URL: ezfiles-0.0.1.tar.gz
- Upload date:
- Size: 2.8 kB
- Tags: Source
- Uploaded using 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
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eaf1527a0f672c0dcf97c12cbd8a3bcca14d6bd6effb85283ef42eedbadc3592
|
|
| MD5 |
f6219b783c60788728316e6ebd866a12
|
|
| BLAKE2b-256 |
2da7753b1764933d7ee1ce9ce0fdb6d4be0d8939ae98af67d96fed7b9572f86b
|
File details
Details for the file ezfiles-0.0.1-py3.7.egg.
File metadata
- Download URL: ezfiles-0.0.1-py3.7.egg
- Upload date:
- Size: 4.2 kB
- Tags: Egg
- Uploaded using 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
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
48fa682f798fa7ab155e8d0db20719fa172e84eeed1e0a31398886c7385826f8
|
|
| MD5 |
9592d6f1d3cbcaec3ae7709f3fbc699c
|
|
| BLAKE2b-256 |
a7cc90454a820130c72b8e7e03e4e5d1ee95b2b30c65a44608e7636c7ee61cb4
|
File details
Details for the file ezfiles-0.0.1-py3-none-any.whl.
File metadata
- Download URL: ezfiles-0.0.1-py3-none-any.whl
- Upload date:
- Size: 2.9 kB
- Tags: Python 3
- Uploaded using 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
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
98a3aa64c288c7ad004c8599b899be31392c70316e993756594d180d6fbeb659
|
|
| MD5 |
81595ae5f1e89db93aff5e206cf4ea7e
|
|
| BLAKE2b-256 |
253ffac882f7ef8f355fd3ef8e8c7f9938d1777176b2d5f13494cd4345f44669
|