1

How can I define static class members by using other static members? for instance:

class Somefuncs:
    @staticmethod
    def foo():
        print('foo was called')
    functs_dict={'foo':Somefuncs.foo}

makes the interpreter raise the Exception: Unresolved reference 'Somefuncs' even though I'm defining funct_dict within the class Somefuncs!

1 Answer 1

3

At this point the class is not really defined.

But you could just write:

class Somefuncs:
    @staticmethod
    def foo():
        print('foo was called')

    functs_dict={'foo': foo}


# Test it
Somefuncs.functs_dict["foo"]()
# Output: foo was called

It always refers to the current class

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.