[Tutor] Module (.py file) that behaves like package
Quentin Agren
quentin.agren at gmail.com
Mon Oct 29 10:10:19 EDT 2018
Hi,
By playing around with importlib I noticed that if you define `__path__ =
[os.path.dirname(__file__)]` in a module named spam.py, then you could `import
spam.spam.spam` or `from spam import spam`. In other words, spam.py behaves
like a package although its loader, if asked, tells that it is not, and
that accordingly you cannot `from . import spam` (in the same file, after
setting `__path__`)
Is this intended behavior? (Maybe I should just get out more...)
Thanks!
Quentin
More information about the Tutor
mailing list