Skip to main content
Help the Python Software Foundation raise $60,000 USD by December 31st!  Building the PSF Q4 Fundraiser

Create properties that are only computed the first time they are called.

Project description

Only compute the value of properties the first time they are called. The easiest way to explain it is by example.

Bad:

class Foo(object):
    def __init__(self):
        self._bar_cache = None

    @property
    def bar(self):
        if self._bar_cache is None:
            self._bar_cache = 2 * 2 * 2
        return self._bar_cache

Good:

from memoize import mproperty

class Foo(object):
    @mproperty
    def bar(self):
        return 2 * 2 * 2

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for memoize, version 1.0.0
Filename, size File type Python version Upload date Hashes
Filename, size memoize-1.0.0.tar.gz (1.1 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page