Feb-25-2018, 02:42 AM
Modules can become large and the author of such a module can use packages
to structure their modules. The python 3 documentation has a top quality
explanation of packages 6.4 Packages[
I have written do nothing code that might give you a better idea of what is
happening. I have created the following folder/file structure. Each
directory I placed an empty __init__.py file permitting me to use the
directory names as if they are packages.
./foo/foo.py
another module qux.py that I wish to use, particularly its method
doNothing() In this case, I can import that code using the dot notation,
because each of my subfolders are serving as containers or rather packages
of other useful modules. In this particular case our bar module is not
installed in the system packages so I prefix bar with .bar as to reference
the current directory.
What I am trying to demonstrate here is that the dots don't always refer to
other packages, they can refer to classes and functions as well. It all
depends on how the code is structured. Not sure if this helps or if it
complicates your current understanding.
to structure their modules. The python 3 documentation has a top quality
explanation of packages 6.4 Packages[
I have written do nothing code that might give you a better idea of what is
happening. I have created the following folder/file structure. Each
directory I placed an empty __init__.py file permitting me to use the
directory names as if they are packages.
Quote: foo
├── bar
│ ├── baz
│ │ ├── __init__.py
│ │ └── qux
│ │ ├── __init__.py
│ │ └── qux.py
│ └── __init__.py
├── foo.py
└── __init__.py
./foo/foo.py
from .bar.baz.qux import Qux myQux = Qux() myQux.doNothing()./foo/bar/baz/quz/qux.py
class Qux: def __init__(self, name): self.name = name def doNothing(self): passWhile writing my foo.py module I remembered that I made a class inside
another module qux.py that I wish to use, particularly its method
doNothing() In this case, I can import that code using the dot notation,
because each of my subfolders are serving as containers or rather packages
of other useful modules. In this particular case our bar module is not
installed in the system packages so I prefix bar with .bar as to reference
the current directory.
What I am trying to demonstrate here is that the dots don't always refer to
other packages, they can refer to classes and functions as well. It all
depends on how the code is structured. Not sure if this helps or if it
complicates your current understanding.