Skip to main content

Provide a helper for creating repr() strings

Project description

trivrepr - a helper for generating repr() strings

[Home | GitLab | PyPI | ReadTheDocs]

Overview

The trivrepr module contains the TrivialRepr class that may be derived from to provide an implementation of __repr__() for simple classes that have all their attributes passed directly to the constructor.

import trivrepr

class KeyValue(trivrepr.TrivialRepr):
    def __init__(self, key, value, more='hi'):
        super(KeyValue, self).__init__()
        self.key = key
        self.value = value
        self.more = more

kv = KeyValue(key='key', value='val')
print(repr(kv))

This program will output:

KeyValue(key='key', value='val', more='hi')

The TrivialReprWithJson class adds a .to_json() method that returns the same fields that __repr__() will output as a dictionary.

Contact

The trivrepr library was written by Peter Pentchev. It is developed in a GitLab repository. This documentation is hosted at Ringlet with a copy at ReadTheDocs.

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

trivrepr-0.2.0.tar.gz (8.4 kB view hashes)

Uploaded Source

Built Distribution

trivrepr-0.2.0-py3-none-any.whl (3.4 kB view hashes)

Uploaded Python 3

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