Code Monkey home page Code Monkey logo

EpicStuff

A few (currently only 3) somewhat useful (Epic) python objects/functions (Stuff)

Installation

pip install epicstuff

Bar

Makes 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 task

with minor extra features (fancier default bar)

Dict

Lets you access a dictionary's keys as attributes

new version

Simpler than Bar (and faster i think) and with more features (basically only recursive conversion) than jdict (and without some of the "extra" stuff)

  • Example:
from epicstuff import Dict

d = Dict({"a": 1, "b": {"c": 2, "d": 3}})

print(d.b.c)  # 2

old version

"Wraps" 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({"a": 1, "b": {"c": 2, "d": 3}}, _convert=False)  # ignore the unexpected-keyword-arg warning

# d._t points to the original dictionary

print(d.b)  # {'c': 2, 'd': 3}

downsides: currently no recursive "wrapping" and is "messier" than the new Dict in VSCode debugger

Timer

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 timer

TODO:

  • 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()

Stuff:

  • Note to self:
    • "self install" using pip install -U -e .
    • build by running python -m build then twine upload dist/*

epicstuff's Projects

epicstuff doesnโ€™t have any public repositories yet.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.