Given the cool nature of this project, I'm surprised they don't offer simply "import wat" with identical usage syntax. Thus inviting curious users to wat/wat in order to discover the trick...
"import wat" would be great, but Python has some restrictions about modules not being callable. That's why I ended up with longer `from wat import wat`. Not sure but maybe this would be more convenient `import wat; wat.wat / object`
Check out the module “q”! It’s callable, its author talked about how great it would be to have a module level __call__ because the way it was made callable is super wonky.
According to the official python documentation [0] of sys.modules:
> This is a dictionary that maps module names to modules which have already been loaded. This can be manipulated to force reloading of modules and other tricks. Thus, the modules dictionary is being used as intended, and it has the desired effect. Nothing wonky about that. Of course, a __call__ method would be better because you could still keep the other functions inside the module. But for a single-function import like "wat" it seems quite natural and sane. [0] https://docs.python.org/fr/3/library/sys.html
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.
This looks super useful, but I was wondering if I'm the only one bothered by this recent trend of overloading completely unrelated operators (here the `/` operator) in the name of legibility.
Wow, this is the kind of tool that would have been a game changer when I was learning python; being able to see what is happening under the covers is part of the critical path for me to learn a language, and native python debugging is underwhelming, at best.
Instead I just installed pry and became a rabid ruby fanboy, but this might get me to give it another go.
Comments (92) 30 threads
Earlier commentsGiven the cool nature of this project, I'm surprised they don't offer simply "import wat" with identical usage syntax. Thus inviting curious users to wat/wat in order to discover the trick...
Edit: Oh, you don't mean in the importing module's globals, you mean `sys.modules`. Yeah that works!
Continue this thread — 1 reply
why do you say it's wonky? it's just
According to the official python documentation [0] of sys.modules:> This is a dictionary that maps module names to modules which have already been loaded. This can be manipulated to force reloading of modules and other tricks.
Thus, the modules dictionary is being used as intended, and it has the desired effect. Nothing wonky about that.
Of course, a __call__ method would be better because you could still keep the other functions inside the module. But for a single-function import like "wat" it seems quite natural and sane.
[0] https://docs.python.org/fr/3/library/sys.html
[0] https://pypi.org/project/snoop/
But I eventually printed that output, and put it in a dir I point my PYTHONPATH to so that I will always have it available.
Let's see if it sticks.
Instead I just installed pry and became a rabid ruby fanboy, but this might get me to give it another go.
All comments shown.
Couldn't load more comments. Check your connection and try again.