Skip to main content

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.

Metadata

Release files for TaskFormatter 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for TaskFormatter 1.0.2
File Size Uploaded
TaskFormatter-1.0.2.tar.gz 3.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for TaskFormatter 1.0.2
File Interpreter ABI Platform
TaskFormatter-1.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 6.6 kB

Release files / TaskFormatter-1.0.2.tar.gz

Download URL TaskFormatter-1.0.2.tar.gz
Size 3.1 kB
Tags Source
SHA-256 checksum
How to use checksums
a25da57f90e059b0c3c8c6b95e12794be2f528e631f6b4231e6f6160459b4d53
BLAKE2b-256 checksum
How to use checksums
aa1a2563d63b5ee4784cbca65ffe4bf72a752a6ea1f47d599e4a21a398b55902
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.4

Release files / TaskFormatter-1.0.2-py3-none-any.whl

Download URL TaskFormatter-1.0.2-py3-none-any.whl
Size 3.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fb285dfe8e73c9ab22189c48efa004774cb28c012f3b88f16f8fe4c2c2094116
BLAKE2b-256 checksum
How to use checksums
3e74a19fc640f637ac3b04593611b8767108c778f75262e3e3beaf4ae630d165
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.4

Release history Release notifications | RSS feed

This release

1.0.2 This release

2 release files

1.0.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page