an unpopular but \"supported\" python hack (see Guido: https://mail.python.org/pipermail/python-ideas/2012-May/014969.html) that enables __getattr__
usage on mo
The problem you are running in to is that in Pythons prior to 3.4 when a module is destroyed (as yours is because you replace it with a class and there are no further references to it), the items in that module's __dict__
are forcibly set to None
.
The workaround, if you need to support Pythons prior to 3.4, is have an import
statement in the class that will replace the module:
class MyClass(object):
import os
def check_os(self):
print(os)
For more info, see this answer about interpreter shutdown.