Create __repr__ automatically or declaratively.
Project description
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.tar.gz
(25.9 kB
view details)
Built Distribution
File details
Details for the file Represent-1.6.0.tar.gz
.
File metadata
- Download URL: Represent-1.6.0.tar.gz
- Upload date:
- Size: 25.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/2.7.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 293dfec8b2e9e2150a21a49bfec2cd009ecb600c8c04f9186d2ad222c3cef78a |
|
MD5 | 6c85d28c613c1f000ae44fb9816c4858 |
|
BLAKE2b-256 | 92266c0a3c6c6806266c9ed1d11d198c64786d76cce67cb482b7985cd787af02 |
Provenance
File details
Details for the file Represent-1.6.0-py2.py3-none-any.whl
.
File metadata
- Download URL: Represent-1.6.0-py2.py3-none-any.whl
- Upload date:
- Size: 13.2 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/2.7.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6000c24f317dbf8b57a116ce4d7e4459fc5900af6a2915c9a2d74456bcc33d3c |
|
MD5 | ffe9a2698e196542d400b38cf63b32e6 |
|
BLAKE2b-256 | 3f42880ddf75691a407d1262e608701c7e531a7b17cb0a34cb40571f57956352 |