Skip to main content

A Python package for function execution status and spinner output

Project description

Formatter and Example

This project demonstrates the use of a Python decorator to format the output of functions, showing a running spinner, and indicating success or failure with colored and formatted text. It includes two files: formatter.py and example.py.

Install

pip install TaskFormatter

Example Output

Files

  1. formatter.py: This file contains the format_output decorator that provides the desired formatting for function output.
  2. example.py: This file demonstrates how to use the format_output decorator by applying it to two example functions, one that succeeds and one that fails.

Features

  • Spinner Animation: Displays a spinner animation while the function is running.
  • Success/Failure Indication: Shows a green checkmark for successful completion and a red cross for failures.
  • Exception Handling: Exceptions are displayed in red and underlined.
  • Function Numbering: Each function is prefixed with a unique number.
  • Text Formatting: Function names are displayed in bold and underlined.
  • Separation of Outputs: Outputs from different functions are separated by a line for clarity.

Usage

1. formatter.py

The format_output decorator is defined in this file. It wraps a function to display the running spinner, success/failure message, and handle exceptions.

2. example.py

The example.py file demonstrates the use of the format_output decorator. It includes two functions, one that succeeds and one that fails, to showcase the decorator's functionality.

from TaskFormatter import format_output
from time import sleep

@format_output
def successful_function():
    print("Starting")
    sleep(2)
    print("Function logic output")

@format_output
def failing_function():
    print("Just Started")
    sleep(2)
    print("Running")
    sleep(2)
    print("Done")
    raise ValueError("Custom Error")

if __name__ == "__main__":
    successful_function()
    try:
        failing_function()
    except Exception as e:
        print("Caught an exception: ", e)

Running the Example

  1. Save formatter.py and example.py in the same directory.
  2. Run example.py using the command:
python example.py

You should see the spinner, success, and failure messages formatted as described, with appropriate separation and formatting for each function's output.

Project details


Download files

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

Source Distribution

TaskFormatter-1.0.2.tar.gz (3.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

TaskFormatter-1.0.2-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

Details for the file TaskFormatter-1.0.2.tar.gz.

File metadata

  • Download URL: TaskFormatter-1.0.2.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.4

File hashes

Hashes for TaskFormatter-1.0.2.tar.gz
Algorithm Hash digest
SHA256 a25da57f90e059b0c3c8c6b95e12794be2f528e631f6b4231e6f6160459b4d53
MD5 a8d9c43dabd55673a1cd0123b4d24b8b
BLAKE2b-256 aa1a2563d63b5ee4784cbca65ffe4bf72a752a6ea1f47d599e4a21a398b55902

See more details on using hashes here.

File details

Details for the file TaskFormatter-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: TaskFormatter-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 3.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.4

File hashes

Hashes for TaskFormatter-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 fb285dfe8e73c9ab22189c48efa004774cb28c012f3b88f16f8fe4c2c2094116
MD5 efc4282c675315fac345ac28c0cf512b
BLAKE2b-256 3e74a19fc640f637ac3b04593611b8767108c778f75262e3e3beaf4ae630d165

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page