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.

Source Distribution

object-colors-1.0.2.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

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

object_colors-1.0.2-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file object-colors-1.0.2.tar.gz.

File metadata

  • Download URL: object-colors-1.0.2.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.2

File hashes

Hashes for object-colors-1.0.2.tar.gz
Algorithm Hash digest
SHA256 524b00011ae168aa7b819c4caa8594361f6c87db850cbbfaa6f2aa0872d66a3b
MD5 48df12bde42ea7f8eaaad43696cd4c32
BLAKE2b-256 fb246dfaa0afe7d17a9fb4ae90b76d85e1bf6811038c51c194bbb0ce9973b627

See more details on using hashes here.

File details

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

File metadata

  • Download URL: object_colors-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.2

File hashes

Hashes for object_colors-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8bf0b268ef27c4643ca5697e94bf76c520d0feeda43cd41dc087625c128bcf99
MD5 1f24ec009c7750fe17c3421cccdbed6f
BLAKE2b-256 ac96a77b195681391b0bcdce74dd2a286636f83b90a3f8e023d8c39bc249aec9

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