PACKAGES .
Importing a Python Package
To use a package in Python, you need to:
• Ensure the package is installed (using pip for external packages).
• Use the import statement in your script.
Standard Import Example:
python
import math # Imports the standard math package
result = math.sqrt(16)
For user-created packages or subpackages:
python
from mypackage.mymodule import myfunction
Pseudocode:
• Install the package, if external.
• Use import package_name or from package.module import item.
Importing a Less Common Package (PrettyTable)
Step 1: Install PrettyTable
bash
pip install prettytable
Step 2: Import and Use
python
from prettytable import PrettyTable
READ THE DOCUMENT AND GENRATE BELOW OUTPUT.
print(table)
OUTPUT :-
+-----------------------+------------+
| Pokemon Name | Type |
+----------------------+------------+
| Pikachu | Electric |
| Squirtle | Water |
| Charmander | Fire |
+----------------------+------------+
Pseudocode:
• Run pip install for the package (e.g., pip install prettytable)
• Use from prettytable import PrettyTable in your code
• Create table objects and operate using its methods
Coffee Machine Program Using Packages (GitHub Version Outline)
• Import logic to bring classes together.
• ALL THE PACKAGES ARE IN GITHUB.
• DOWNLOAD AND CREATE OUTPUT WHICH WE HAVE GENERATE IN PREVIOUS COFFEE_MACHINE
Top comments (1)
HOPE THIS HELP, Check my Github for Code Snippet.