2 ms·
There's a very cool (and succinct) blog post[1] showing how to abuse this in an interesting way where you can put the code of a module into a string and load it
by tyingq 5y ago
There's a very cool (and succinct) blog post[1] showing how to abuse this in an interesting way where you can put the code of a module into a string and load it that way.
Not something I'd use in production, but it's a very clear way to see how both "finding a module" and "loading a module" works under the covers.
[1] https://cprohm.de/blog/python-packages-in-a-single-file/ https://cprohm.de/blog/python-packages-in-a-single-file/
Edit: As an aside, I much prefer the way Perl does things in this space. It's much easier to define multiple packages either within a single file or across different files, and much clearer about what's happening underneath.