Introduction

_images/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).