A few somewhat useful (Epic) python objects/functions (Stuff)
pip install epicstuffLets you access a dictionary's keys as attributes
Points to a target instead of converting it into a (new) Dict object. Useful for when your "target" is say, a CommentedMap and you don't want to loose the comments.
- Example:
from epicstuff import Dict
d = Dict({})
d.x = 1Simpler (less features) than Box (and faster i think) but with more features (recursive conversion and creation on access) than jdict (and without some of the "extra" stuff)
- Example:
from epicstuff import Dict
d = Dict({"a": 1, "b": {"c": 2, "d": 3}}, _convert=None)
print(d.b.c) # 2Easily install terminal-wide rich.traceback and use helpers to ensure pretty tracebacks with async functions.
- Example:
from epicstuff import run_install_trace- or:
from epicstuff import rich_trace
@rich_trace
async def some_func():
raise Exception
some_func()- or:
@rich_trace(_return=0)
async def some_func():
raise Exception
some_func()- or:
with rich_trace():
raise ExceptionMakes using nested progress bars from rich.progress easier
- Example:
basically replaces
from rich.progress import Progress
with Progress() as progress:
task = progress.add_task("task", total=100)
for i in range(100):
sub_task = progress.add_task("subtask", total=100)
for j in range(100):
time.sleep(0.01) # some task
progress.update(sub_task, advance=1)
progress.remove_task(sub_task)
progress.update(task, advance=1)with
from epicstuff import Bar
with Bar() as bar:
for i in bar(range(100)):
for j in bar(range(100), transient=True):
time.sleep(0.01) # some taskwith minor extra features (fancier default bar)
a simple timer to time execution of code a code segment
- Example:
from epicstuff import timer
with timer():
pass # some code
# outputs: Time elapsed: 0.0 seconds
# message can be changed by passing a string with {} to timerAn autoformatting string. Removes extra indent and leading/trailing newlines.
- Example:
from epicstuff import s
string = s('''
line 1
line 2
line 3
''') + 'line 4'
print(s)
# line 1
# line 2
# line 3
# line 4make function ignore extra arguments instead of raising an error.
- Example:
from epicstuff import perm
def tmp(a, b=2): ...
perm(tmp)(1, 2, b=3, c=5) # this will run without raising TypeErrorextra functions:
open: overwritingopenwithPath.openandencoding='utf8'(also acceptsstr)wrap: just a renamedfunctools.partialrmap:mapbut recursive for lists and dicts- takes
listordictand 2 functions, will apply function 1 to all keys and function 2 to all values
- takes
Tee: Text stream that writes to multiple underlying streams. (Example: redirect stdout to terminal and a file)Pointer: an object you can kinda use like a pointer. (Examplenumber = Pointer(5), number._t = 6)
- when doing bar in bar with the second bar being transient, make so that the dots continue from where the previous bar left off
- implement auto transient for bar in bar
- add and implement simple=False for .Bar.track()
- Note to self:
- "self install" using
pip install -U -e . - upload by running
python -m buildthentwine upload --skip-existing dist/*
- "self install" using