I am writing a simple python module of the form
toys/
A.py
B.py
.
.
.
My goal is to be able to access any toy in toys as simply as import toys
such that toy.A
exists. But dir(toys)
does not include A, given the directory structure shown above. Instead, I have to import each toy individually, import toy.A
.
Of course I can force each toy to be included by including from . import A
in toy/__init__.py
. But I'm trying to set up a workflow in which I add arbitrarily many toys; having to add a line explicitly for each new toy is cumbersome. How can I implicitly attach each new toy to toys
? Is there a graceful way to attach a module's submodules automatically?
I tried putting from . import *
inside of __init__.py
, but this had no effect, not to mention that it's considered an antipattern.