pretty classes - pretty easy. (created by auxilium)
Project description
Python Project prettyclass
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 http://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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file prettyclass-0.1.zip
.
File metadata
- Download URL: prettyclass-0.1.zip
- Upload date:
- Size: 14.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5913c8ad319b5725c39589b476233e7e8df727eda7c644da3063fee00a232705 |
|
MD5 | ebc0b41f9e5a58d4ba155a6279c55f85 |
|
BLAKE2b-256 | 8219bb92f617c280087a1d67d989b0a19ac4c91892035198e0963eb7d342fb35 |