Create __repr__ automatically or declaratively.
Project description
Represent
Installation
$ pip install represent
Automatic Generation
from represent import autorepr
@autorepr
class Rectangle:
def __init__(self, name, color, width, height):
self.name = name
self.color = color
self.width = width
self.height = height
rect = Rectangle('Timothy', 'red', 15, 4.5)
print(rect)
Rectangle(name='Timothy', color='red', width=15, height=4.5)
Declarative Generation
from represent import ReprHelperMixin
class ContrivedExample(ReprHelperMixin, object):
def __init__(self, description, radians, shape, color, miles):
self.description = description
self.degrees = radians * 180 / 3.141592654
self.shape = shape
self._color = color
self.km = 1.60934 * miles
def _repr_helper_(self, r):
r.positional_from_attr('description')
r.positional_with_value(self.degrees * 3.141592654 / 180)
r.keyword_from_attr('shape')
r.keyword_from_attr('color', '_color')
r.keyword_with_value('miles', self.km / 1.60934)
ce = ContrivedExample('does something', 0.345, 'square', 'red', 22)
print(ce)
from IPython.lib.pretty import pprint
pprint(ce)
ContrivedExample('does something', 0.345, shape='square', color='red', miles=22.0)
ContrivedExample('does something',
0.345,
shape='square',
color='red',
miles=22.0)
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
Represent-1.6.0.post0.tar.gz
(23.4 kB
view details)
Built Distribution
File details
Details for the file Represent-1.6.0.post0.tar.gz
.
File metadata
- Download URL: Represent-1.6.0.post0.tar.gz
- Upload date:
- Size: 23.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 026c0de2ee8385d1255b9c2426cd4f03fe9177ac94c09979bc601946c8493aa0 |
|
MD5 | e9a54492225eebd6b4a1427409b6425e |
|
BLAKE2b-256 | e1ecea9c10142e6d65e9e12eea4678bf531b65e07a491e0071358d4ea3bae901 |
Provenance
File details
Details for the file Represent-1.6.0.post0-py2.py3-none-any.whl
.
File metadata
- Download URL: Represent-1.6.0.post0-py2.py3-none-any.whl
- Upload date:
- Size: 12.4 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 99142650756ef1998ce0661568f54a47dac8c638fb27e3816c02536575dbba8c |
|
MD5 | ccd1af10540479f843f46777dbb63e0e |
|
BLAKE2b-256 | 1cbe18cafb0b26abdff7e3e2944efd1c91de56d25b36445b23ec9d349a9fa70d |