-
You like the safety of
with
statements, just not in your code: letjust
take care of it. -
You like a computer to figure out how to load a file based on extension.
-
You like sensible defaults for reading and writing.
just.read
a file like:
some_txt = just.read("myfile.txt")
some_json = just.read("myfile.json")
some_yaml = just.read("myfile.yaml")
some_csv = just.read("myfile.csv")
some_pkl = just.read("myfile.pkl")
Multi-read is also possible:
txts = just.multi_read("file*.txt")
jsons = just.multi_read("*.json")
Multi-read is different as of 0.2.25, it now returns a dictionary instead of list; {"file.txt": "file_contents"}
just.write
a file like:
just.write(some_txt, "myfile.txt")
just.write(some_json, "myfile.json")
just.write(some_yaml, "myfile.yaml")
just.write(some_csv, "myfile.csv")
just.write(some_pkl, "myfile.pkl")
data = just.read("notexisting.txt", no_exist=[])
Like this you can still write a for loop, as you expect this file to be filled in a second run of the script.
The logic of finding a root file is the following:
- Environment variable
JUST_PATH
, if not set - Searching upwards to a
.just
file, if not found - The path where the script gets executed from
The rationale is that you can refer to 'data/images' from anywhere in your project. It will be relative to the "just path".
data = just.write("data/txt/deep/1.png", mkdir_no_exist=True) # default
There's also an option to skip writing if the file exists, but this is not True
by default.
data = just.write("data/txt/deep/1.png", skip_if_exist=False) # default
from just import glob
glob("**.txt")
# lists filesnames
Code is under CI, tested to be working on python 2.7/3.3+:
pip install just
-
Add streaming reader/writers,
just.iread
andjust.iwrite
-
Add optional backends like urllib, requests, bs4, lxml, pandas
-
Add requests.get/post to return "aware" content, e.g. json/txt