Skip to main content

Adding colours to Python simplified into a single class

Project description

Installation

pip install object-colors

Setup

from object_colors import Color
c = Color()

Usage

  • key-values

    Match effects with effect and colors with text and background

    keys = ["text", "effect", "background"]
    values = {
        "colors": ["black", "red", "green", "yellow", "blue", "purple", "cyan", "white"]
        "effects": ['none', "bold", 'bright', "underline", "negative"]
    }
    

Methods

  • set()

    Set values with keyword arguments

    >>> c.set(text="red", effect="bold", background="blue")
    >>> c.set("red", "bold", "blue")
    >>> c.set(114)
    >>> print(c.__dict__)
    
    {'text': 1, 'effect': 1, 'background': 4}
    

    Set a new class with a keyword (any key) followed by a dict value

    >>> c.set(
            red={"text": "red"},
            bold_red={"text": "red", "effect": "bold"},
            yellow={"text": "yellow"}
        )
    >>> c.yellow.set(effect="bold")
    >>> print(c.__dict__)
    
    {
        'text': 1,
        'effect': 1,
        'background': 4,
        'red': <object_colors.Color object at 0x0000020C10D06080>,
        'bold_red': <object_colors.Color object at 0x0000020C10D066D8>,
        'yellow': <object_colors.Color object at 0x0000020C10D06B00>
    }
    
    >>> print(c.yellow.__dict__)
    
    {'text': 3, 'effect': 1, 'background': 0}
    
  • print()

    Instance includes enhanced print() function for color output

    >>> c.print("no color print")
    >>> c.red.print("red print", flush=True)
    >>> c.yellow.print("yellow print", end="")
    
  • get()

    Store values for multicolored printing

    >>> bullet = c.red.get("[!] ")
    >>> warning = c.yellow("Warning")
    >>> print(bullet + warning)
    
  • pop()

    Remove unused attributes

    >>> c.pop("bold_red")
    >>> print(c.__dict__)
    
    {
        'text': 1,
        'effect': 1,
        'background': 4,
        'red': <object_colors.Color object at 0x0000020C10D06080>,
        'yellow': <object_colors.Color object at 0x0000020C10D06B00>
    }
    

    Or create new instances

    >>> red = c.pop("red")
    >>> print(c.__dict__)
    
    {
        'text': 1,
        'effect': 1,
        'background': 4,
        'yellow': <object_colors.Color object at 0x0000020C10D06B00>
    }
    
    >>> print(red.__dict__)
    
    {'text': 1, 'effect': 0, 'background': 0}
    
    >>> red.print()
    >>> red.get()
    >>> red.set()
    

Project details


Download files

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

Files for object-colors, version 1.0.2
Filename, size File type Python version Upload date Hashes
Filename, size object_colors-1.0.2-py3-none-any.whl (5.9 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size object-colors-1.0.2.tar.gz (5.0 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page