(continued from previous pageinvoke __init__ spam(print("__init__ " as b__init__ invoke __call__ ( print("__call__ " as b__call__ context management protocol the 'withstatement allows statements to execute under the control over another object known as "context managerthe context manager has two methods __enter__ and __exit__ as shown in table methods __enter__(self__exit__(selftypevaluetbtable methods for context management description called when entering new context called when leaving the context if an exception occurred'type''valueand 'tbhave the exception typevalue and traceback information primary use of the context management interface is to allow for simplified resource control on objects involving system state filesnetworks connection and database etc by implementing this interfacean object can safely clean up resources when execution leaves context in which the object is being used object inspection and dir(the dir(function is used to inspect the objectswhich returns all the attributes of the objects to provide only useful information about the objectit can be overwritten using __dir__(selfas shown belowclass spamdef __init__(selfa= = )self self def __call__(selfa= = )self self def __dir__(self)return ['__init__''__call__''add more' spam(dir( ['__call__''__init__''add more' special methods