Skip to main content

pretty classes - pretty easy. (created by auxilium)

Project description

logo.png

Python Project prettyclass

GitHubWorkflow Read the Docs GitHub GitHub release PyPI Version PyPI - Python Version PyPI Downloads

Introduction

To import the project simply type

>>> import prettyclass

after installation.

>>> from prettyclass import prettyclass

>>> @prettyclass()
... class ABC:
...     def __init__(self, a, *b, c, d=1, e, **f):
...         '''creates ABC instance'''

The decorator adds automaticly all argument fields as attributes.

>>> abc = ABC(1, 2, [3, 4], c=5, d=6, e=7, g='A', h='B')
>>> abc.__dict__
{'a': 1, 'b': (2, [3, 4]), 'c': 5, 'd': 6, 'e': 7, 'f': {'g': 'A', 'h': 'B'}}

>>> abc.a, abc.b, abc.c, abc.d, abc.e, abc.f
(1, (2, [3, 4]), 5, 6, 7, {'g': 'A', 'h': 'B'})

and returns a pretty nice representation of an instance

>>> abc
ABC(1, 2, [3, 4], c=5, d=6, e=7, g='A', h='B')

Note the difference between ‘str’ and ‘repr’

>>> str(abc)
'ABC(1, 2, [3, 4], c=5, d=6, e=7, g=A, h=B)'

>>> repr(abc)
"ABC(1, 2, [3, 4], c=5, d=6, e=7, g='A', h='B')"

Copy works by default, too.

>>> from copy import copy
>>> copy(abc)
ABC(1, 2, [3, 4], c=5, d=6, e=7, g='A', h='B')

Note, the string representation commits entries which coincide with defaults

>>> ABC(1, 2, [3, 4], c=5, d=1, e=7, g='A', h='B')
ABC(1, 2, [3, 4], c=5, e=7, g='A', h='B')

Documentation

More documentation available at https://prettyclass.readthedocs.io

Install

The latest stable version can always be installed or updated via pip:

$ pip install prettyclass

License

Code and documentation are available according to the license (see LICENSE file in repository).

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

prettyclass-0.1.1.zip (15.0 kB view details)

Uploaded Source

File details

Details for the file prettyclass-0.1.1.zip.

File metadata

  • Download URL: prettyclass-0.1.1.zip
  • Upload date:
  • Size: 15.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.11

File hashes

Hashes for prettyclass-0.1.1.zip
Algorithm Hash digest
SHA256 9498d29945e91a77043bda56185991815b1902fa8cab7cea5b0eacb8f5d5bc5e
MD5 469be41f40ae81b756512c00367b8b40
BLAKE2b-256 4ffba6325d0374dbf5b2ce2a87bfe7fb03bf7f316de40e8716d6eb0ad7a1e59f

See more details on using hashes here.

Supported by

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