How can I check if a class has been instantiated in Python ?

Viewed 6526

In one of my classes, I am printing data from another class that is yet to be initialized.I only want to print that data once the class has been initialized.Is there any way check if the class has been instantiated?

3 Answers

Two functions that return true if you pass an undeclared class, and false if it is instantiated:

import inspect
inspect.isclass(myclass)

or

isinstance(myclass, type)

In general, if it's not a type (i.e. undeclared class), it's an instantiated type.

Related