Skip to main content

Helpers for creation of nicer repr() and str().

Project description

This module exposes a few functions and a class decorator to make the task of writing __repr__() and __str__() for custom classes much easier. It will display a list of nicely formatted (attr, val) pairs with custmizable separator and formatting for each pair.

Let’s look at an example:

from rr import pretty

class foo(object):
    __str__ = pretty.str
    __repr__ = pretty.repr
    __info__ = pretty.info(["x", "y", "z"])

    def __init__(self, x, y, z):
        self.x = x
        self.y = y
        self.z = z

f = foo(1, 2, 3)
print repr(f)  # see for yourself :)
print str(f)

Now, let’s do the same, only this time we’ll use the klass() class decorator:

from rr import pretty

@pretty.klass
class foo(object):
    def __init__(self, x, y, z):
        self.x = x
        self.y = y
        self.z = z

f = foo(1, 2, 3)
print repr(f)  # see for yourself :)
print str(f)

We even left out the attribute list, and pretty.info() (which is what pretty.klass() uses behind the scenes) builds it for us. That’s it! You get nice __repr__() and __str__() methods for free.

Installation

>From PyPI (“stable” release):

pip install rr.pretty

>From the Git repo:

git clone https://github.com/2xR/rr.pretty.git
pip install ./rr.pretty

Contributing

Contributions are welcome through github pull requests (tests would be nice to have… :P)

And if you’re using the library and would like to say “thanks!” and/or keep me working on it, why not buy me a beer?

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

rr.pretty-0.1.0.zip (7.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rr.pretty-0.1.0-py2-none-any.whl (6.5 kB view details)

Uploaded Python 2

File details

Details for the file rr.pretty-0.1.0.zip.

File metadata

  • Download URL: rr.pretty-0.1.0.zip
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for rr.pretty-0.1.0.zip
Algorithm Hash digest
SHA256 359569472c243644715e773d34cfe19d7d5a8dbfdb8f36ff8060dad9c336115c
MD5 125639e1fbf894ff5e7c12bfb82033d4
BLAKE2b-256 f6336d4c4e0bfbd9948d410998005e94d1e0812f2c861a12f7df67c510cc61dd

See more details on using hashes here.

File details

Details for the file rr.pretty-0.1.0-py2-none-any.whl.

File metadata

File hashes

Hashes for rr.pretty-0.1.0-py2-none-any.whl
Algorithm Hash digest
SHA256 e671cedd08b3350780baafde3cef73efd30c61f1c0b98d0fa78bdf47036e4b5c
MD5 15e9ec99fb2ef82ac0e9422bcc90d3d1
BLAKE2b-256 9a369540cce35610f41dc33f76b98fb000d53f298eccaf6402a38c9e37a20c67

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page