I have used this SO answer to dynamically generate a module x and register it in sys.modules. I want a piece of code to run automatically when an import is called on this module. so for example I want print "you just imported module x". So it behaves like:
>>> import x
you just imported module x
How do I get this behavior?
class Foo:in the exampleexecis called not when the module is imported.