Introducing Packages
00:00 Modules allow you to divide a program into individual files that can be reused as needed. Related code can be organized into a single module and kept separate from other code. Packages take this organizational structure one step further.
00:17
In Python, a package is basically a folder that contains one or more Python modules. On the slide, you can see an example of a package. The structure looks like this. There is a folder named mypackage/
, and in the folder there are three Python files. One is named module1.py
, and another is named module2.py
.
00:37
And there is also a Python file that looks a bit different. There is a file named __init__.py
, or short __init__.py
.
00:50
To make a folder a regular Python package, the folder must contain an __init__
module. The __init__.py
module doesn’t need to contain any code. It only needs to exist so that Python recognizes the mypackage/
folder as a Python package.
01:11 With this package structure in mind, let’s create your first package.
alphafox28js on Dec. 5, 2023
This Course would be more beneficial in learning right before the OOP Course. I believe the 2% of unusable code I have from the OOP Exercises and Farm would have been correct if the Import Methods were defined before hand since different Methods will help if multiple names of the same are given… Other than that, Notes taken and good info.
Become a Member to join the conversation.
alphafox28js on Dec. 5, 2023
Method 4 was skipped over. I did try it, however it produced an AttributeError: ‘function’ object has no attribute ‘add’…
Not sure why VS Code did not like it :)