trivrepr — a helper for generating Python repr() strings

Description | Download | Acknowledgements

Description

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

Downloading trivrepr

The trivrepr homepage is here; the development history may be seen in the change log.

The latest release is trivrepr-0.1.1:

Older versions of trivrepr

Acknowledgements

Thanks go to (in no particular order):

Description | Download | Acknowledgements

Contacts: Peter Pentchev

This site was created with VIM! :wq