Skip to main content

Implement comparison magic methods in one line!

Project description


Implement comparison magic methods in one line!


from comparative import compare_by

@compare_by("hour", "minute", "second")
class Clock:

    def __int__(self, hour=0, minute=0, second=0):
        self.hour = hour
        self.minute = mintue
        self.second = second

    def __repr__(self):
        return ("Clock(h={0.hour:}, m={0.minute:02d}, "

    def __str__(self):
        return "{0.hour:02d}:{0.minute:02d}:{0.second:02d}".format(self)

Just Add Water

>>> clock1 = Clock(8, 0, 0)
>>> clock2 = Clock(8, 0, 1)
>>> clock3 = Clock(8, 0, 0)
>>> clock1 < clock2
>>> clock1 == clock2
>>> clock1 == clock3


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

comparative-0.0.2.tar.gz (1.9 kB view hashes)

Uploaded source

Built Distributions

comparative-0.0.2-py3.7.egg (3.3 kB view hashes)

Uploaded 3 7

comparative-0.0.2-py3-none-any.whl (14.7 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page