'Python Package Creation

I have a package i am trying to create. The directory hierarchy looks like this.

Package/
    __init__.py
    Part1/
        __init__.py
        item.py
        load_items.py
    Part2/
        __init__.py
        section.py
    Part3/
        __init__.py
        mappings/
            file1.txt
            file2.txt
            ...
            file10.txt
        map.py
        unmapped.txt

I have some other file main.py that is not in the package and inside I have put

import Package
print(dir(Package))

The output from this is

['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__']

however I was expecting to see "Part1", "Part2", and "Part3" in this list. I also tried

print(Package.Part1)

and I got an attribute error: Package has no attribute Part1.

This is the first package I have made and I am also unsure why __init__.py is needed in every directory? Or perhaps this is wrong and it isn't. I've read a bunch of the other questions on stack overflow but none of them have really helped me understand. Basically, I'm looking for whether my package is structured correctly and why when I do dir(Package) the parts of it are not listed.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source