3 ms·
Thank you all, I learned from you that it's possible to have a callable module. Although `sys.modules[__name__] = wat` looks like a black magic and I'm a bit af
by igrek51 2y ago
Thank you all, I learned from you that it's possible to have a callable module. Although `sys.modules[__name__] = wat` looks like a black magic and I'm a bit afraid of locking out to other importable things in this package, I think I'll go for it.
- notpushkin 2y agoIt is kinda black magic, and I think it's not something people would expect. You can import other things just fine though: import sys def wat(): print("wat") def bar(): print("bar") wat.wat = wat wat.bar = bar sys.modules[__name__] = wat ... >>> import wat >>> wat() wat >>> from wat import bar >>> bar() bar Edit: I think a better way would be to instead add __call__ to the current module somehow though.