Skip to content

classtools.postint

sikvelsigma edited this page Aug 18, 2022 · 4 revisions

Contains:

  • class PostInit

Inhereting from PostInit adds a call to __postinit__ method after __init__ call was completed

  • metaclass PostInitMeta

Inhereting from PostInitMeta is not advised


Usage:

from pyuseful.classtools.postinit import PostInit

class Test(PostInit):
    # postinit is called immediately after init
    def __init__(self):
        print("this prints on init")
        self.a = 1

    def __postinit__(self):
        print("this prints after init is done")
        print(self.a)

t = Test()

Clone this wiki locally