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-2.1.tar.gz
(19.0 kB
view details)
Built Distribution
File details
Details for the file Represent-2.1.tar.gz
.
File metadata
- Download URL: Represent-2.1.tar.gz
- Upload date:
- Size: 19.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0b2d015c14e7ba6b3b5e6a7ba131a952013fe944339ac538764ce728a75dbcac |
|
MD5 | 5d98bd63a32e59e0bdb6a2945a85b246 |
|
BLAKE2b-256 | 271f6a057fd4353ce17820681c776cfa2deeb3dc0eb9e5757e5c31ccc88b72ea |
Provenance
File details
Details for the file Represent-2.1-py3-none-any.whl
.
File metadata
- Download URL: Represent-2.1-py3-none-any.whl
- Upload date:
- Size: 9.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 94fd22d7fec378240c598b20b233f80545ec7eb1131076e2d3d759cee9be2588 |
|
MD5 | b0e36fbaefed66aabbf24afb28510bbd |
|
BLAKE2b-256 | a2609bb91d2a6ab018238a290d9244e61121a645bbf57c0b36b305a091e14ed0 |