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 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


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.zip (14.9 kB view details)

Uploaded Source

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

Hashes for prettyclass-0.1.zip
Algorithm Hash digest
SHA256 5913c8ad319b5725c39589b476233e7e8df727eda7c644da3063fee00a232705
MD5 ebc0b41f9e5a58d4ba155a6279c55f85
BLAKE2b-256 8219bb92f617c280087a1d67d989b0a19ac4c91892035198e0963eb7d342fb35

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