Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Can I call a static method from outside a class without initializing the class?

class BaseIndicesLinker:

    def __init__(
        self,
        date: int)

    @staticmethod
    def some_static_function(i: int):
        return datetime.datetime(...)



def retrieve_index_codes_from_index_objects(session, date):

    # converting date to expected datetime format
    datetime = some_static_function(date)

    return all_index_codes

The above doesn’t work, because some_static_function is ‘not defined’.

So I suppose my question is, is it possible to call on the static function without initializing the class BaseIndicesLinker?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Yes, you can call a static method without initializing the class. you just need to use the class name followed by the method name.

datetime = BaseIndicesLinker.some_static_function(date)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading