Part 5 - Building Out the Project (Classes, Methods, Functions, and Code Organization)
Channel: Your Daily Dose of Python
Date: 25/08/2022

Part 1 - Setting Up Python Dev Environment: https://youtu.be/li44EFjVBlU
Part 2 - Part 2 - OS Navigation and File Manipulation: https://youtu.be/9QU-3yQmNYg
Part 3 - The Whys, the Hows, and the Whats of Learning Python: https://youtu.be/n4poGFHgyZg
Part 4 - Building Out the Project (Scoping and Design): https://youtu.be/ymo9nEYgqOk
Part 5 - Building Out the Project (Classes, Methods, Functions, and Code Organization): https://youtu.be/eQRBQ3gkmeM

Step #1: Verify that the different project packages are detected (any folder with the "__init__.py" file)

import sys

print(sys.path)

Step #2: Create the "MenuCreator" class under the "menu" directory:

nano -c menu_creator.py

#Class that creates the application menu
class MenuCreator:
 pass
 
Step #3: Create methods inside the "MenuCreator" class:

class MenuCreator:
 def __init__(self):
  pass   
 
 def menu_create(self):
  pass
 
 def menu_selector(self):
  pass
 
 def menu_sanitize(self, entry_list):
  pass

Step #4: Import the "MenuCreator" class from the "menu_creator" module from the "menu" package in the main application file:

from menu.menu_creator import MenuCreator

Step #5: Create an instance of the "MenuCreator" class a "main_menu":

def host_util():
 main_menu = MenuCreator()
 print(main_menu)
 print(dir(main_menu)

Summary:
1. Learned about Python class(es), how to create and use 

2. Learned about the difference between a function and a method

3. Learned how to import custom modules into the main application file

4. Learned the importance of "Write Once Use Many" principle

Definitions:

Instantiation - the construction/creation of a class object/class instance

Constructor - the "def __init__(self)" method is a reserved method in python that sets the value(s) of the class attributes. The attributes are accessed via the "self" keyword.

Global variable - are variables that are created outside of a function

Package - is a grouping/collection of Python module(s) which exist(s) in the same folder/directory that has the __init__.py file 

Module - is a file containing Python definitions and statements. The file name is the module name with the suffix .py appended

Functions in Python:
 - are outside a class
 - are not linked to anything
 - can be executed just by calling with its name
 - can have zero parameters (arguments)
 - can not access or modify class attributes
 - are independent of classes

Methods in Python:
 - are inside a class
 - are linked to a class
 - cannot be executed without class instance
 - will need the "self" as first parameter (argument)
 - can access or modify class attributes
 - are totally dependent on classes

Resources:
Python Comments: https://www.w3schools.com/python/python_comments.asp

Python Class/Methods: https://www.w3schools.com/python/python_classes.asp

Python Scope: https://www.w3schools.com/python/python_scope.asp

Python Functions: https://www.w3schools.com/python/python_functions.asp

Python Indentations: https://peps.python.org/pep-0008/#indentation

Python Package, Module, and Class Names: https://peps.python.org/pep-0008/#package-and-module-names