News for hackers. Stuff that matters.
Re:Show HN: Wat – Deep inspection of Python objects by igrek51 on Friday July 26, 2024 @05:34AM (#41077140)
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.
Re:Show HN: Wat – Deep inspection of Python objects by notpushkin on Friday July 26, 2024 @07:33AM (#41077751)
It 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.