cant't use package internals
Andrej Viktorovich wrote:
> I have Python package tst in my workspace.
> tst has files:
> content of __init__.py:
> print("importing Tst")
> content of tst.py:
> class Tst:
> def __init__(self):
> print("init Tst")
> I run python console in workspace directory. I do
> Run without errors. I was expected "importing Tst" to be printed, but
> nothing happened. Why?
You may have a second tst.py, e. g. in your working directory, that is found
first and thus shadows the tst package. A variant of that explanation would
be that the tst folder is your working directory and you are importing the
tst submodule directly instead as part of a package.
In the interactive interpreter you can use the tst.__file__ attribute to
find out what is actually going on.
To make things a bit clearer I recommend that you give package and submodule
different names, at least while you are experimenting.
> I run
> and got error:
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> AttributeError: module 'tst' has no attribute 'tst'
> Wh it not finds Tst class?
Submodules of a package are not imported automatically.
t = tst.tst.Tst()