Learning Python from the ground up
Welcome to my structured path for learning Python — from the basics to web development with CGI and Flask.
This repository is both a learning journal and a reference library, showing my progression step by step.
A structured learning project covering Python basics through databases and web integration.
Sensitive credentials are never committed — they are managed securely using .env files and excluded from Git with .gitignore.
python-learning-journey/
├── 01_basics/
│ ├── hello_world.py
│ ├── variables.py
│ ├── input_output.py
│ └── math_operations.py
├── 02_control_flow/
│ ├── if_else.py
│ ├── loops.py
│ └── break_continue.py
├── 03_functions/
│ ├── functions_intro.py
│ ├── lambda_functions.py
│ ├── scope.py
│ ├── docstrings.py
│ ├── args_kwargs.py
│ └── recursion_examples.py
├── 04_oop/
│ ├── classes_objects.py
│ ├── inheritance.py
│ ├── polymorphism.py
│ ├── encapsulation.py
│ └── class_methods_static.py
├── 05_web_basics/
│ ├── cgi_hello.py
│ ├── cgi_form.py
│ ├── cgi_env.py
│ └── cgi_error.py
├── 06_flask_intro/
│ ├── app.py
│ ├── form_demo.py
│ └── templates/
│ ├── home.html
│ ├── about.html
│ └── contact.html
├── 07_databases/
│ ├── mysql_demo.py
│ └── templates/
│ └── users.html
└── README.md
hello_world.py→ Prints "Hello World" to demonstrate Python’s simplest output.variables_demo.py→ Shows variable assignment and basic data types.loops_demo.py→ Demonstratesforandwhileloops with simple examples.
list_examples.py→ Basic list operations: append, slice, iterate.dict_examples.py→ Key/value storage and retrieval with dictionaries.set_examples.py→ Demonstrates uniqueness and set operations.
functions_demo.py→ Defines and calls functions with parameters and return values.modules_demo.py→ Imports built‑in modules and shows modular code structure.
class_demo.py→ Defines a simple class with attributes and methods.inheritance_demo.py→ Demonstrates subclassing and method overriding.polymorphism_demo.py→ Shows how different classes can share behavior.
cgi_hello.py→ A simple “Hello World” CGI script that outputs static HTML.cgi_form.py→ Handles user input from an HTML form and dynamically responds.cgi_env.py→ Displays CGI environment variables passed by Apache.cgi_error.py→ Demonstrates error handling in CGI scripts.
app.py→ Flask app with multiple routes (/,/about,/contact) demonstrating navigation and template rendering.templates/home.html→ Home page template with links to About and Contact.templates/about.html→ About page template describing the app.templates/contact.html→ Contact form template that accepts name, email, and message, and displays a confirmation.form_demo.py→ Standalone script demonstrating GET/POST form handling directly withrender_template_string.
This section introduces database integration with Flask using MySQL.
mysql_demo.py→ Flask app that connects to MySQL usingmysqlclient(MySQLdb) and environment variables for credentials.templates/users.html→ Template that lists users retrieved from the database.
- Create the database and table in MySQL:
CREATE DATABASE python_learning; USE python_learning; CREATE TABLE users ( id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(80) ); INSERT INTO users (name) VALUES ('Alice'), ('Bob'), ('Charlie'); ## Database Configuration & Security
This project uses a config.py file to manage database connection settings.
Sensitive information such as usernames and passwords are never committed to Git. Instead, they are stored in a local .env file and loaded at runtime using python-dotenv.
.envcontains environment variables (e.g.,MYSQL_USER,MYSQL_PASSWORD).config.pyloads these variables securely withdotenv..gitignoreexcludes bothconfig.pyand.envto prevent accidental commits.
MYSQL_HOST=localhost
MYSQL_USER=root
MYSQL_PASSWORD=your_secure_password
MYSQL_DATABASE=python_learning
---
## ✅ Why This Helps
- Shows recruiters I understand **security and reproducibility**.
- Makes it clear collaborators should set up their own `.env` file.
- Reinforces that your repo is clean — no secrets in history.
---
Perfect — here’s a concise **Setup Instructions** section I can drop into your README so collaborators (or recruiters) know exactly how to run your database demo securely:
---
## ⚙️ Setup Instructions
To run the database examples in `07_databases`, follow these steps:
1. **Install dependencies**
```bash
pip install python-dotenv mysql-connector-python-
Create a
.envfile at the project root (same level asREADME.md):MYSQL_HOST=localhost MYSQL_USER=root MYSQL_PASSWORD=your_secure_password MYSQL_DATABASE=python_learning
-
Verify
.gitignoreexcludes sensitive files:07_databases/config.py .env -
Run the demo
python 07_databases/mysql_demo.py
-
Confirm environment variables are loaded
python -c "import config; print(config.MYSQL)"→ should print your connection dictionary with values from
.env.
- Keeps credentials out of GitHub history.
- Makes setup reproducible for anyone cloning your repo.
- Shows recruiters I understand secure, professional workflows.
🔄 Workflow Diagram +------------------+ | .env | | (stores secrets) | +------------------+ | v +------------------+ | config.py | | loads with | | python-dotenv | +------------------+ | v +------------------+ | mysql_demo.py | | uses MYSQL dict | | for connection | +------------------+