2 ms·
for those wondering how "import madeupname" works, basically the incantation is: # unless __name__ == "__main__" self = sys.modules[__name__] # Se
by riffraff 14y ago
for those wondering how "import madeupname" works, basically the incantation is:
# unless __name__ == "__main__"
self = sys.modules[__name__]
# SelfWrapper has a custom __getattr__
sys.modules[__name__] = SelfWrapper(self)
which seems somewhat unpythonesque (aren't import hooks supposed to be used for this?) but it's cool and I hadn't seen it before.
- fijal 14y agoimport hooks leave crap in your global state. this only modifies sys.modules, which is probably a much better option.