π PYTHON β DAY 41 STUDY MATERIAL
β¨ Topic: Introduction to Tkinter (GUI Programming)
βββββββββββββββββββ
π What is Tkinter?
Tkinter is Pythonβs built-in GUI (Graphical User Interface) library.
It allows you to create:
β Desktop Applications
β Forms
β Buttons & Labels
β Mini Software Projects
No installation required β (Built-in with Python)
βββββββββββββββββββ
π₯οΈ Creating First GUI Window
import tkinter as tk
root = tk.Tk()
root.title("My First App")
root.geometry("400x300")
root.mainloop()
This creates a simple window π₯
βββββββββββββββββββ
πΉ Adding a Label
import tkinter as tk
root = tk.Tk()
label = tk.Label(root, text="Hello Python GUI")
label.pack()
root.mainloop()
βββββββββββββββββββ
πΉ Adding a Button
import tkinter as tk
def click():
print("Button Clicked!")
root = tk.Tk()
btn = tk.Button(root, text="Click Me", command=click)
btn.pack()
root.mainloop()
βββββββββββββββββββ
πΉ Adding Entry (Input Box)
import tkinter as tk
def show():
print(entry.get())
root = tk.Tk()
entry = tk.Entry(root)
entry.pack()
btn = tk.Button(root, text="Submit", command=show)
btn.pack()
root.mainloop()
βββββββββββββββββββ
π Layout Methods
β pack() β Simple layout
β grid() β Table layout
β place() β Custom position
Example (grid):
label.grid(row=0, column=0)
βββββββββββββββββββ
π§ Why Tkinter?
β Build Desktop Apps
β Create Login Forms
β Build Calculator
β Create Management Systems
βββββββββββββββββββ
π Practice Tasks β Day 41
β Create window
β Add label
β Add button
β Take user input
β Try grid layout
βββββββββββββββββββ
π― Day 41 Goal
β Create basic GUI
β Add widgets
β Understand event handling
ββββββββββββββββββ
π Next Topic β Day 42
π₯ Building Calculator using Tkinter
β¨ Stay Connected | Keep Coding
π TechByWebCoder
β¨ Topic: Introduction to Tkinter (GUI Programming)
βββββββββββββββββββ
π What is Tkinter?
Tkinter is Pythonβs built-in GUI (Graphical User Interface) library.
It allows you to create:
β Desktop Applications
β Forms
β Buttons & Labels
β Mini Software Projects
No installation required β (Built-in with Python)
βββββββββββββββββββ
π₯οΈ Creating First GUI Window
import tkinter as tk
root = tk.Tk()
root.title("My First App")
root.geometry("400x300")
root.mainloop()
This creates a simple window π₯
βββββββββββββββββββ
πΉ Adding a Label
import tkinter as tk
root = tk.Tk()
label = tk.Label(root, text="Hello Python GUI")
label.pack()
root.mainloop()
βββββββββββββββββββ
πΉ Adding a Button
import tkinter as tk
def click():
print("Button Clicked!")
root = tk.Tk()
btn = tk.Button(root, text="Click Me", command=click)
btn.pack()
root.mainloop()
βββββββββββββββββββ
πΉ Adding Entry (Input Box)
import tkinter as tk
def show():
print(entry.get())
root = tk.Tk()
entry = tk.Entry(root)
entry.pack()
btn = tk.Button(root, text="Submit", command=show)
btn.pack()
root.mainloop()
βββββββββββββββββββ
π Layout Methods
β pack() β Simple layout
β grid() β Table layout
β place() β Custom position
Example (grid):
label.grid(row=0, column=0)
βββββββββββββββββββ
π§ Why Tkinter?
β Build Desktop Apps
β Create Login Forms
β Build Calculator
β Create Management Systems
βββββββββββββββββββ
π Practice Tasks β Day 41
β Create window
β Add label
β Add button
β Take user input
β Try grid layout
βββββββββββββββββββ
π― Day 41 Goal
β Create basic GUI
β Add widgets
β Understand event handling
ββββββββββββββββββ
π Next Topic β Day 42
π₯ Building Calculator using Tkinter
β¨ Stay Connected | Keep Coding
π TechByWebCoder
π PYTHON β DAY 42 STUDY MATERIAL
β¨ Mini Project: Calculator using Tkinter
βββββββββββββββββββ
π Project Goal
Create a simple calculator that:
β Takes two numbers
β Performs addition, subtraction, multiplication, division
β Displays result on screen
Concepts Used:
β Tkinter GUI
β Functions
β Event Handling
βββββββββββββββββββ
π₯οΈ Basic Calculator Code
import tkinter as tk
def calculate(operation):
num1 = float(entry1.get())
num2 = float(entry2.get())
if operation == "+":
result = num1 + num2
elif operation == "-":
result = num1 - num2
elif operation == "*":
result = num1 * num2
elif operation == "/":
result = num1 / num2
result_label.config(text="Result: " + str(result))
root = tk.Tk()
root.title("Calculator")
root.geometry("300x250")
tk.Label(root, text="Enter First Number").pack()
entry1 = tk.Entry(root)
entry1.pack()
tk.Label(root, text="Enter Second Number").pack()
entry2 = tk.Entry(root)
entry2.pack()
tk.Button(root, text="Add", command=lambda: calculate("+")).pack()
tk.Button(root, text="Subtract", command=lambda: calculate("-")).pack()
tk.Button(root, text="Multiply", command=lambda: calculate("*")).pack()
tk.Button(root, text="Divide", command=lambda: calculate("/")).pack()
result_label = tk.Label(root, text="Result: ")
result_label.pack()
root.mainloop()
βββββββββββββββββββ
β Improvement: Add Error Handling
Add try-except inside calculate():
try:
num1 = float(entry1.get())
num2 = float(entry2.get())
except ValueError:
result_label.config(text="Invalid Input β")
βββββββββββββββββββ
π¨ Bonus Improvements
β Add clear button
β Use grid layout
β Add better UI design
β Add keyboard support
ββββββββββββββββββ
π Practice Tasks β Day 42
β Build calculator
β Add error handling
β Improve UI
β Add clear button
βββββββββββββββββββ
π― Day 42 Goal
β Build complete GUI project
β Use functions with buttons
β Handle user input errors
βββββββββββββββββββ
π Next Topic β Day 43
π₯ Introduction to SQLite Database in Python
β¨ Stay Connected | Keep Coding
π TechByWebCoder
β¨ Mini Project: Calculator using Tkinter
βββββββββββββββββββ
π Project Goal
Create a simple calculator that:
β Takes two numbers
β Performs addition, subtraction, multiplication, division
β Displays result on screen
Concepts Used:
β Tkinter GUI
β Functions
β Event Handling
βββββββββββββββββββ
π₯οΈ Basic Calculator Code
import tkinter as tk
def calculate(operation):
num1 = float(entry1.get())
num2 = float(entry2.get())
if operation == "+":
result = num1 + num2
elif operation == "-":
result = num1 - num2
elif operation == "*":
result = num1 * num2
elif operation == "/":
result = num1 / num2
result_label.config(text="Result: " + str(result))
root = tk.Tk()
root.title("Calculator")
root.geometry("300x250")
tk.Label(root, text="Enter First Number").pack()
entry1 = tk.Entry(root)
entry1.pack()
tk.Label(root, text="Enter Second Number").pack()
entry2 = tk.Entry(root)
entry2.pack()
tk.Button(root, text="Add", command=lambda: calculate("+")).pack()
tk.Button(root, text="Subtract", command=lambda: calculate("-")).pack()
tk.Button(root, text="Multiply", command=lambda: calculate("*")).pack()
tk.Button(root, text="Divide", command=lambda: calculate("/")).pack()
result_label = tk.Label(root, text="Result: ")
result_label.pack()
root.mainloop()
βββββββββββββββββββ
β Improvement: Add Error Handling
Add try-except inside calculate():
try:
num1 = float(entry1.get())
num2 = float(entry2.get())
except ValueError:
result_label.config(text="Invalid Input β")
βββββββββββββββββββ
π¨ Bonus Improvements
β Add clear button
β Use grid layout
β Add better UI design
β Add keyboard support
ββββββββββββββββββ
π Practice Tasks β Day 42
β Build calculator
β Add error handling
β Improve UI
β Add clear button
βββββββββββββββββββ
π― Day 42 Goal
β Build complete GUI project
β Use functions with buttons
β Handle user input errors
βββββββββββββββββββ
π Next Topic β Day 43
π₯ Introduction to SQLite Database in Python
β¨ Stay Connected | Keep Coding
π TechByWebCoder
π PYTHON β DAY 43 STUDY MATERIAL
β¨ Topic: Introduction to SQLite Database in Python
βββββββββββββββββββ
π What is SQLite?
SQLite is a lightweight database that is stored in a single file.
β No server required
β Built into Python
β Perfect for small applications
Used in:
π± Mobile apps
π» Desktop apps
π§ Prototyping databases
βββββββββββββββββββ
πΉ Import SQLite Module
SQLite comes built-in with Python.
import sqlite3
βββββββββββββββββββ
πΉ Creating a Database
import sqlite3
conn = sqlite3.connect("student.db")
print("Database created successfully")
This creates a file student.db
βββββββββββββββββββ
πΉ Creating a Table
import sqlite3
conn = sqlite3.connect("student.db")
cursor = conn.cursor()
cursor.execute(""" CREATE TABLE student( id INTEGER PRIMARY KEY, name TEXT, age INTEGER ) """)
conn.commit()
conn.close()
βββββββββββββββββββ
πΉ Inserting Data
import sqlite3
conn = sqlite3.connect("student.db")
cursor = conn.cursor()
cursor.execute("INSERT INTO student VALUES(1,'Soham',20)")
conn.commit()
conn.close()
βββββββββββββββββββ
πΉ Reading Data
conn = sqlite3.connect("student.db")
cursor = conn.cursor()
cursor.execute("SELECT * FROM student")
rows = cursor.fetchall()
for row in rows:
print(row)
βββββββββββββββββββ
πΉ Updating Data
cursor.execute( "UPDATE student SET age=21 WHERE id=1"
βββββββββββββββββββ
πΉ Deleting Data
cursor.execute( "DELETE FROM student WHERE id=1" )
βββββββββββββββββββ
π§ Why SQLite is Useful?
β Build small database applications
β Store app data locally
β Practice SQL with Python
βββββββββββββββββββ
π Practice Tasks β Day 43
β Create database file
β Create student table
β Insert 3 records
β Display all records
β Update a record
βββββββββββββββββββ
π― Day 43 Goal
β Connect Python with database
β Perform CRUD operations
β Understand cursor & commit
βββββββββββββββββββ
π Next Topic β Day 44
π₯ Building Student Management System with SQLite
β¨ Stay Connected | Keep Coding
π TechByWebCoder
β¨ Topic: Introduction to SQLite Database in Python
βββββββββββββββββββ
π What is SQLite?
SQLite is a lightweight database that is stored in a single file.
β No server required
β Built into Python
β Perfect for small applications
Used in:
π± Mobile apps
π» Desktop apps
π§ Prototyping databases
βββββββββββββββββββ
πΉ Import SQLite Module
SQLite comes built-in with Python.
import sqlite3
βββββββββββββββββββ
πΉ Creating a Database
import sqlite3
conn = sqlite3.connect("student.db")
print("Database created successfully")
This creates a file student.db
βββββββββββββββββββ
πΉ Creating a Table
import sqlite3
conn = sqlite3.connect("student.db")
cursor = conn.cursor()
cursor.execute(""" CREATE TABLE student( id INTEGER PRIMARY KEY, name TEXT, age INTEGER ) """)
conn.commit()
conn.close()
βββββββββββββββββββ
πΉ Inserting Data
import sqlite3
conn = sqlite3.connect("student.db")
cursor = conn.cursor()
cursor.execute("INSERT INTO student VALUES(1,'Soham',20)")
conn.commit()
conn.close()
βββββββββββββββββββ
πΉ Reading Data
conn = sqlite3.connect("student.db")
cursor = conn.cursor()
cursor.execute("SELECT * FROM student")
rows = cursor.fetchall()
for row in rows:
print(row)
βββββββββββββββββββ
πΉ Updating Data
cursor.execute( "UPDATE student SET age=21 WHERE id=1"
βββββββββββββββββββ
πΉ Deleting Data
cursor.execute( "DELETE FROM student WHERE id=1" )
βββββββββββββββββββ
π§ Why SQLite is Useful?
β Build small database applications
β Store app data locally
β Practice SQL with Python
βββββββββββββββββββ
π Practice Tasks β Day 43
β Create database file
β Create student table
β Insert 3 records
β Display all records
β Update a record
βββββββββββββββββββ
π― Day 43 Goal
β Connect Python with database
β Perform CRUD operations
β Understand cursor & commit
βββββββββββββββββββ
π Next Topic β Day 44
π₯ Building Student Management System with SQLite
β¨ Stay Connected | Keep Coding
π TechByWebCoder
π PYTHON β DAY 44 STUDY MATERIAL
β¨ Mini Project: Student Management System using SQLite
βββββββββββββββββββ
π Project Goal
Create a simple Student Management System that can:
β Add student record
β View student records
β Update student details
β Delete student record
Concepts Used:
β SQLite Database
β CRUD Operations
β Python Functions
βββββββββββββββββββ
π Step 1: Create Database & Table
import sqlite3
conn = sqlite3.connect("student.db")
cursor = conn.cursor()
cursor.execute(""" CREATE TABLE IF NOT EXISTS student( id INTEGER PRIMARY KEY, name TEXT, age INTEGER, course TEXT ) """)
conn.commit()
βββββββββββββββββββ
β Step 2: Insert Student Data
def add_student(id, name, age, course):
cursor.execute( "INSERT INTO student VALUES(?,?,?,?)", (id, name, age, course) )
conn.commit()
Example:
add_student(1,"Soham",20,"Python")
βββββββββββββββββββ
π Step 3: View Students
def view_students():
cursor.execute("SELECT * FROM student")
rows = cursor.fetchall()
for row in rows:
print(row)
βββββββββββββββββββ
β Step 4: Update Student
def update_student(id, age):
cursor.execute( "UPDATE student SET age=? WHERE id=?", (age,id) )
conn.commit()
βββββββββββββββββββ
β Step 5: Delete Student
def delete_student(id):
cursor.execute( "DELETE FROM student WHERE id=?", (id,) )
conn.commit()
βββββββββββββββββββ
π§ How the System Works?
1οΈβ£ User adds student
2οΈβ£ Data stored in database
3οΈβ£ User can view/update/delete records
Real-world concept:
β Database CRUD operations
βββββββββββββββββββ
π¨ Bonus Improvements
β Add menu system
β Add input validation
β Connect with Tkinter GUI
β Export data to CSV
βββββββββββββββββββ
π Practice Tasks β Day 44
β Create student database
β Insert 5 students
β Display all records
β Update one record
β Delete one record
βββββββββββββββββββ
π― Day 44 Goal
β Build database project
β Understand CRUD operations
β Use SQLite with Python
βββββββββββββββββββ
π Next Topic β Day 45
π₯ Web Scraping using Python (BeautifulSoup)
β¨ Stay Connected | Keep Coding
π TechByWebCoder
β¨ Mini Project: Student Management System using SQLite
βββββββββββββββββββ
π Project Goal
Create a simple Student Management System that can:
β Add student record
β View student records
β Update student details
β Delete student record
Concepts Used:
β SQLite Database
β CRUD Operations
β Python Functions
βββββββββββββββββββ
π Step 1: Create Database & Table
import sqlite3
conn = sqlite3.connect("student.db")
cursor = conn.cursor()
cursor.execute(""" CREATE TABLE IF NOT EXISTS student( id INTEGER PRIMARY KEY, name TEXT, age INTEGER, course TEXT ) """)
conn.commit()
βββββββββββββββββββ
β Step 2: Insert Student Data
def add_student(id, name, age, course):
cursor.execute( "INSERT INTO student VALUES(?,?,?,?)", (id, name, age, course) )
conn.commit()
Example:
add_student(1,"Soham",20,"Python")
βββββββββββββββββββ
π Step 3: View Students
def view_students():
cursor.execute("SELECT * FROM student")
rows = cursor.fetchall()
for row in rows:
print(row)
βββββββββββββββββββ
β Step 4: Update Student
def update_student(id, age):
cursor.execute( "UPDATE student SET age=? WHERE id=?", (age,id) )
conn.commit()
βββββββββββββββββββ
β Step 5: Delete Student
def delete_student(id):
cursor.execute( "DELETE FROM student WHERE id=?", (id,) )
conn.commit()
βββββββββββββββββββ
π§ How the System Works?
1οΈβ£ User adds student
2οΈβ£ Data stored in database
3οΈβ£ User can view/update/delete records
Real-world concept:
β Database CRUD operations
βββββββββββββββββββ
π¨ Bonus Improvements
β Add menu system
β Add input validation
β Connect with Tkinter GUI
β Export data to CSV
βββββββββββββββββββ
π Practice Tasks β Day 44
β Create student database
β Insert 5 students
β Display all records
β Update one record
β Delete one record
βββββββββββββββββββ
π― Day 44 Goal
β Build database project
β Understand CRUD operations
β Use SQLite with Python
βββββββββββββββββββ
π Next Topic β Day 45
π₯ Web Scraping using Python (BeautifulSoup)
β¨ Stay Connected | Keep Coding
π TechByWebCoder
π PYTHON β DAY 45 STUDY MATERIAL
β¨ Topic: Web Scraping using Python (BeautifulSoup)
βββββββββββββββββββ
π What is Web Scraping?
Web scraping means extracting data from websites automatically using code.
Used for:
β Data collection
β Price tracking
β News aggregation
β Market research
βββββββββββββββββββ
π¦ Required Libraries
Install libraries:
pip install requests
pip install beautifulsoup4
Import in Python:
import requests
from bs4 import BeautifulSoup
βββββββββββββββββββ
π Step 1: Get Website HTML
import requests
url = "https://example.comβ οΏ½"
response = requests.get(url)
html = response.text
print(html)
This fetches the HTML source of the webpage.
βββββββββββββββββββ
π Step 2: Parse HTML using BeautifulSoup
from bs4 import BeautifulSoup
soup = BeautifulSoup(html, "html.parser")
print(soup.title)
Extracts the title of the webpage.
βββββββββββββββββββ
πΉ Extract Specific Data
Example: Get all headings
for heading in soup.find_all("h1"):
print(heading.text)
βββββββββββββββββββ
πΉ Extract Links from Page
for link in soup.find_all("a"):
print(link.get("href"))
βββββββββββββββββββ
πΉ Extract Paragraph Text
for p in soup.find_all("p"):
print(p.text)
βββββββββββββββββββ
β Important Note
Always check a websiteβs robots.txt before scraping.
Some websites do not allow scraping.
βββββββββββββββββββ
π§ Real-world Uses of Web Scraping
β Job listing collectors
β Product price trackers
β News aggregators
β Social media analysis
βββββββββββββββββββ
π Practice Tasks β Day 45
β Fetch website HTML
β Extract title
β Extract all links
β Extract paragraph text
βββββββββββββββββββ
π― Day 45 Goal
β Understand web scraping concept
β Use BeautifulSoup
β Extract structured data
βββββββββββββββββββ
π
π₯ Automating Tasks with Python (Automation Scripts)
β¨ Stay Connected | Keep Coding
π TechByWebCoder
β¨ Topic: Web Scraping using Python (BeautifulSoup)
βββββββββββββββββββ
π What is Web Scraping?
Web scraping means extracting data from websites automatically using code.
Used for:
β Data collection
β Price tracking
β News aggregation
β Market research
βββββββββββββββββββ
π¦ Required Libraries
Install libraries:
pip install requests
pip install beautifulsoup4
Import in Python:
import requests
from bs4 import BeautifulSoup
βββββββββββββββββββ
π Step 1: Get Website HTML
import requests
url = "https://example.comβ οΏ½"
response = requests.get(url)
html = response.text
print(html)
This fetches the HTML source of the webpage.
βββββββββββββββββββ
π Step 2: Parse HTML using BeautifulSoup
from bs4 import BeautifulSoup
soup = BeautifulSoup(html, "html.parser")
print(soup.title)
Extracts the title of the webpage.
βββββββββββββββββββ
πΉ Extract Specific Data
Example: Get all headings
for heading in soup.find_all("h1"):
print(heading.text)
βββββββββββββββββββ
πΉ Extract Links from Page
for link in soup.find_all("a"):
print(link.get("href"))
βββββββββββββββββββ
πΉ Extract Paragraph Text
for p in soup.find_all("p"):
print(p.text)
βββββββββββββββββββ
β Important Note
Always check a websiteβs robots.txt before scraping.
Some websites do not allow scraping.
βββββββββββββββββββ
π§ Real-world Uses of Web Scraping
β Job listing collectors
β Product price trackers
β News aggregators
β Social media analysis
βββββββββββββββββββ
π Practice Tasks β Day 45
β Fetch website HTML
β Extract title
β Extract all links
β Extract paragraph text
βββββββββββββββββββ
π― Day 45 Goal
β Understand web scraping concept
β Use BeautifulSoup
β Extract structured data
βββββββββββββββββββ
π
Next Topic β Day 46π₯ Automating Tasks with Python (Automation Scripts)
β¨ Stay Connected | Keep Coding
π TechByWebCoder
PYTHON β DAY 46 STUDY MATERIAL
β¨ Topic: Automating Tasks with Python
βββββββββββββββββββ
π What is Automation?
Automation means using code to perform repetitive tasks automatically.
Instead of doing work manually, Python can do it faster and automatically.
Examples:
β Renaming multiple files
β Sending emails automatically
β Data backup scripts
β Auto downloading files
βββββββββββββββββββ
π¦ Useful Python Modules for Automation
β os β File operations
β shutil β File moving/copying
β schedule β Task scheduling
β smtplib β Email automation
β pyautogui β Keyboard & mouse automation
βββββββββββββββββββ
π Example 1: List Files in Folder
import os
files = os.listdir()
for file in files:
print(file)
Shows all files in the current directory.
βββββββββββββββββββ
β Example 2: Rename Multiple Files
import os
files = os.listdir()
for i, file in enumerate(files):
os.rename(file, f"file_{i}.txt")
This renames files automatically π₯
βββββββββββββββββββ
π Example 3: Copy Files Automatically
import shutil
shutil.copy("source.txt", "backup.txt")
Used for file backup automation.
βββββββββββββββββββ
β° Example 4: Schedule Tasks
Install schedule library:
pip install schedule
Example:
import schedule
import time
def job():
print("Task executed")
schedule.every(5).seconds.do(job)
while True:
schedule.run_pending()
time.sleep(1)
Runs task every 5 seconds.
βββββββββββββββββββ
π§ Real-world Automation Examples
β Auto email sender
β Auto report generator
β File organizer
β Social media automation
βββββββββββββββββββ
π Practice Tasks β Day 46
β List files in directory
β Rename files automatically
β Copy file backup
β Schedule a task
βββββββββββββββββββ
π― Day 46 Goal
β Understand automation concept
β Use OS & file modules
β Create simple automation scripts
βββββββββββββββββββ
π Next Topic β Day 47
π₯ Sending Emails using Python
β¨ Stay Connected | Keep Coding
π TechByWebCoder
β¨ Topic: Automating Tasks with Python
βββββββββββββββββββ
π What is Automation?
Automation means using code to perform repetitive tasks automatically.
Instead of doing work manually, Python can do it faster and automatically.
Examples:
β Renaming multiple files
β Sending emails automatically
β Data backup scripts
β Auto downloading files
βββββββββββββββββββ
π¦ Useful Python Modules for Automation
β os β File operations
β shutil β File moving/copying
β schedule β Task scheduling
β smtplib β Email automation
β pyautogui β Keyboard & mouse automation
βββββββββββββββββββ
π Example 1: List Files in Folder
import os
files = os.listdir()
for file in files:
print(file)
Shows all files in the current directory.
βββββββββββββββββββ
β Example 2: Rename Multiple Files
import os
files = os.listdir()
for i, file in enumerate(files):
os.rename(file, f"file_{i}.txt")
This renames files automatically π₯
βββββββββββββββββββ
π Example 3: Copy Files Automatically
import shutil
shutil.copy("source.txt", "backup.txt")
Used for file backup automation.
βββββββββββββββββββ
β° Example 4: Schedule Tasks
Install schedule library:
pip install schedule
Example:
import schedule
import time
def job():
print("Task executed")
schedule.every(5).seconds.do(job)
while True:
schedule.run_pending()
time.sleep(1)
Runs task every 5 seconds.
βββββββββββββββββββ
π§ Real-world Automation Examples
β Auto email sender
β Auto report generator
β File organizer
β Social media automation
βββββββββββββββββββ
π Practice Tasks β Day 46
β List files in directory
β Rename files automatically
β Copy file backup
β Schedule a task
βββββββββββββββββββ
π― Day 46 Goal
β Understand automation concept
β Use OS & file modules
β Create simple automation scripts
βββββββββββββββββββ
π Next Topic β Day 47
π₯ Sending Emails using Python
β¨ Stay Connected | Keep Coding
π TechByWebCoder
π PYTHON β DAY 47 STUDY MATERIAL
β¨ Topic: Sending Emails using Python
βββββββββββββββββββ
π Why Send Emails with Python?
Python can automate email tasks like:
β Sending notifications
β Sending reports automatically
β Sending OTP messages
β Marketing email automation
βββββββββββββββββββ
π¦ Required Module
Python provides built-in module:
smtplib
Used to send emails using SMTP (Simple Mail Transfer Protocol).
βββββββββββββββββββ
π§ Basic Email Sending Example
import smtplib
sender = "your_email@gmail.com"
receiver = "receiver_email@gmail.com"
password = "your_app_password"
message = "Hello! This email was sent using Python."
server = smtplib.SMTP("smtp.gmail.com", 587)
server.starttls()
server.login(sender, password)
server.sendmail(sender, receiver, message)
server.quit()
print("Email Sent Successfully β ")
βββββββββββββββββββ
π Important: Use App Password
For Gmail you must use App Password, not your main password.
Steps:
1οΈβ£ Go to Google Account
2οΈβ£ Security β App Passwords
3οΈβ£ Generate password for Mail
4οΈβ£ Use that password in Python
βββββββββββββββββββ
π Sending Email with Subject
from email.mime.text import MIMEText
message = MIMEText("Hello from Python!")
message["Subject"] = "Python Email Test"
message["From"] = sender
message["To"] = receiver
βββββββββββββββββββ
π Sending Email with Attachment (Concept)
Modules used:
β email
β smtplib
β MIMEBase
This allows sending:
π PDFs
π· Images
π Reports
βββββββββββββββββββ
π§ Real-world Uses
β Daily report email automation
β Alert systems
β Customer notifications
β Password reset emails
βββββββββββββββββββ
π Practice Tasks β Day 47
β Send simple email
β Add subject line
β Send email to yourself
β Try adding attachment
βββββββββββββββββββ
π― Day 47 Goal
β Understand SMTP
β Send email using Python
β Learn email automation basics
βββββββββββββββββββ
π Next Topic β Day 48
π₯ Multithreading in Python
β¨ Stay Connected | Keep Coding
π TechByWebCoder
β¨ Topic: Sending Emails using Python
βββββββββββββββββββ
π Why Send Emails with Python?
Python can automate email tasks like:
β Sending notifications
β Sending reports automatically
β Sending OTP messages
β Marketing email automation
βββββββββββββββββββ
π¦ Required Module
Python provides built-in module:
smtplib
Used to send emails using SMTP (Simple Mail Transfer Protocol).
βββββββββββββββββββ
π§ Basic Email Sending Example
import smtplib
sender = "your_email@gmail.com"
receiver = "receiver_email@gmail.com"
password = "your_app_password"
message = "Hello! This email was sent using Python."
server = smtplib.SMTP("smtp.gmail.com", 587)
server.starttls()
server.login(sender, password)
server.sendmail(sender, receiver, message)
server.quit()
print("Email Sent Successfully β ")
βββββββββββββββββββ
π Important: Use App Password
For Gmail you must use App Password, not your main password.
Steps:
1οΈβ£ Go to Google Account
2οΈβ£ Security β App Passwords
3οΈβ£ Generate password for Mail
4οΈβ£ Use that password in Python
βββββββββββββββββββ
π Sending Email with Subject
from email.mime.text import MIMEText
message = MIMEText("Hello from Python!")
message["Subject"] = "Python Email Test"
message["From"] = sender
message["To"] = receiver
βββββββββββββββββββ
π Sending Email with Attachment (Concept)
Modules used:
β email
β smtplib
β MIMEBase
This allows sending:
π PDFs
π· Images
π Reports
βββββββββββββββββββ
π§ Real-world Uses
β Daily report email automation
β Alert systems
β Customer notifications
β Password reset emails
βββββββββββββββββββ
π Practice Tasks β Day 47
β Send simple email
β Add subject line
β Send email to yourself
β Try adding attachment
βββββββββββββββββββ
π― Day 47 Goal
β Understand SMTP
β Send email using Python
β Learn email automation basics
βββββββββββββββββββ
π Next Topic β Day 48
π₯ Multithreading in Python
β¨ Stay Connected | Keep Coding
π TechByWebCoder
π PYTHON β DAY 48 STUDY MATERIAL
β¨ Topic: Multithreading in Python
βββββββββββββββββββ
π What is Multithreading?
Multithreading allows a program to run multiple tasks at the same time.
Instead of executing tasks one by one, Python can run them concurrently.
Example:
β Download multiple files simultaneously
β Handle multiple users in a server
β Perform background tasks
βββββββββββββββββββ
β‘ Thread vs Process
Thread β Lightweight task inside a program
Process β Independent running program
Multithreading helps improve performance for many tasks.
βββββββββββββββββββ
π¦ Threading Module
Python provides built-in module:
import threading
βββββββββββββββββββ
πΉ Creating a Thread
import threading
def task():
print("Thread is running")
t = threading.Thread(target=task)
t.start()
This starts a new thread.
βββββββββββββββββββ
πΉ Running Multiple Threads
import threading
def task():
print("Thread executed")
t1 = threading.Thread(target=task)
t2 = threading.Thread(target=task)
t1.start()
t2.start()
Both tasks run simultaneously π₯
βββββββββββββββββββ
πΉ Using join()
join() makes main program wait for thread to finish.
t1.start()
t1.join()
print("Thread finished")
βββββββββββββββββββ
πΉ Example with Delay
import threading
import time
def task():
print("Task started")
time.sleep(2)
print("Task completed")
t = threading.Thread(target=task)
t.start()
βββββββββββββββββββ
π§ Where Multithreading is Used?
β Web servers
β Game development
β File downloads
β Background processing
βββββββββββββββββββ
π Practice Tasks β Day 48
β Create one thread
β Run two threads
β Use join()
β Add delay using time.sleep()
βββββββββββββββββββ
π― Day 48 Goal
β Understand threading concept
β Create and run threads
β Improve program efficiency
βββββββββββββββββββ
π Next Topic β Day 49
π₯ Multiprocessing in Python
β¨ Stay Connected | Keep Coding
π TechByWebCoder
β¨ Topic: Multithreading in Python
βββββββββββββββββββ
π What is Multithreading?
Multithreading allows a program to run multiple tasks at the same time.
Instead of executing tasks one by one, Python can run them concurrently.
Example:
β Download multiple files simultaneously
β Handle multiple users in a server
β Perform background tasks
βββββββββββββββββββ
β‘ Thread vs Process
Thread β Lightweight task inside a program
Process β Independent running program
Multithreading helps improve performance for many tasks.
βββββββββββββββββββ
π¦ Threading Module
Python provides built-in module:
import threading
βββββββββββββββββββ
πΉ Creating a Thread
import threading
def task():
print("Thread is running")
t = threading.Thread(target=task)
t.start()
This starts a new thread.
βββββββββββββββββββ
πΉ Running Multiple Threads
import threading
def task():
print("Thread executed")
t1 = threading.Thread(target=task)
t2 = threading.Thread(target=task)
t1.start()
t2.start()
Both tasks run simultaneously π₯
βββββββββββββββββββ
πΉ Using join()
join() makes main program wait for thread to finish.
t1.start()
t1.join()
print("Thread finished")
βββββββββββββββββββ
πΉ Example with Delay
import threading
import time
def task():
print("Task started")
time.sleep(2)
print("Task completed")
t = threading.Thread(target=task)
t.start()
βββββββββββββββββββ
π§ Where Multithreading is Used?
β Web servers
β Game development
β File downloads
β Background processing
βββββββββββββββββββ
π Practice Tasks β Day 48
β Create one thread
β Run two threads
β Use join()
β Add delay using time.sleep()
βββββββββββββββββββ
π― Day 48 Goal
β Understand threading concept
β Create and run threads
β Improve program efficiency
βββββββββββββββββββ
π Next Topic β Day 49
π₯ Multiprocessing in Python
β¨ Stay Connected | Keep Coding
π TechByWebCoder
π PYTHON β DAY 49 STUDY MATERIAL
β¨ Topic: Multiprocessing in Python
βββββββββββββββββββ
π What is Multiprocessing?
Multiprocessing means running multiple processes simultaneously using multiple CPU cores.
Unlike multithreading, each process runs independently.
Example:
β Video processing
β Large data analysis
β Machine learning tasks
β High-performance computing
βββββββββββββββββββ
β‘ Thread vs Process
Thread β Runs inside same program memory
Process β Runs in separate memory space
Multiprocessing uses multiple CPU cores, making programs faster.
βββββββββββββββββββ
π¦ Multiprocessing Module
Python provides built-in module:
import multiprocessing
βββββββββββββββββββ
πΉ Creating a Process
import multiprocessing
def task():
print("Process running")
p = multiprocessing.Process(target=task)
p.start()
This creates a new process.
βββββββββββββββββββ
πΉ Running Multiple Processes
import multiprocessing
def task():
print("Process executed")
p1 = multiprocessing.Process(target=task)
p2 = multiprocessing.Process(target=task)
p1.start()
p2.start()
Both processes run in parallel π₯
βββββββββββββββββββ
πΉ Using join()
join() waits for process completion.
p1.start()
p1.join()
print("Process finished")
βββββββββββββββββββ
πΉ Example with CPU Work
import multiprocessing
import time
def task():
for i in range(5):
print("Processing", i)
time.sleep(1)
p = multiprocessing.Process(target=task)
p.start()
βββββββββββββββββββ
π§ Where Multiprocessing is Used?
β Data science
β Machine learning
β Image processing
β Scientific computing
βββββββββββββββββββ
π Practice Tasks β Day 49
β Create a process
β Run two processes
β Use join()
β Add loop processing
βββββββββββββββββββ
π― Day 49 Goal
β Understand multiprocessing concept
β Run parallel processes
β Use multiple CPU cores
βββββββββββββββββββ
π Next Topic β Day 50
π₯ Logging in Python
β¨ Stay Connected | Keep Coding
π TechByWebCoder
β¨ Topic: Multiprocessing in Python
βββββββββββββββββββ
π What is Multiprocessing?
Multiprocessing means running multiple processes simultaneously using multiple CPU cores.
Unlike multithreading, each process runs independently.
Example:
β Video processing
β Large data analysis
β Machine learning tasks
β High-performance computing
βββββββββββββββββββ
β‘ Thread vs Process
Thread β Runs inside same program memory
Process β Runs in separate memory space
Multiprocessing uses multiple CPU cores, making programs faster.
βββββββββββββββββββ
π¦ Multiprocessing Module
Python provides built-in module:
import multiprocessing
βββββββββββββββββββ
πΉ Creating a Process
import multiprocessing
def task():
print("Process running")
p = multiprocessing.Process(target=task)
p.start()
This creates a new process.
βββββββββββββββββββ
πΉ Running Multiple Processes
import multiprocessing
def task():
print("Process executed")
p1 = multiprocessing.Process(target=task)
p2 = multiprocessing.Process(target=task)
p1.start()
p2.start()
Both processes run in parallel π₯
βββββββββββββββββββ
πΉ Using join()
join() waits for process completion.
p1.start()
p1.join()
print("Process finished")
βββββββββββββββββββ
πΉ Example with CPU Work
import multiprocessing
import time
def task():
for i in range(5):
print("Processing", i)
time.sleep(1)
p = multiprocessing.Process(target=task)
p.start()
βββββββββββββββββββ
π§ Where Multiprocessing is Used?
β Data science
β Machine learning
β Image processing
β Scientific computing
βββββββββββββββββββ
π Practice Tasks β Day 49
β Create a process
β Run two processes
β Use join()
β Add loop processing
βββββββββββββββββββ
π― Day 49 Goal
β Understand multiprocessing concept
β Run parallel processes
β Use multiple CPU cores
βββββββββββββββββββ
π Next Topic β Day 50
π₯ Logging in Python
β¨ Stay Connected | Keep Coding
π TechByWebCoder
π PYTHON β DAY 50 STUDY MATERIAL
β¨ Topic: Logging in Python
βββββββββββββββββββ
π What is Logging?
Logging is used to record events that happen while a program runs.
Instead of using print() everywhere, developers use logging to track:
β Errors
β Warnings
β Debug information
β Application activity
βββββββββββββββββββ
π¦ Logging Module
Python provides a built-in module:
import logging
βββββββββββββββββββ
πΉ Basic Logging Example
import logging
logging.basicConfig(level=logging.DEBUG)
logging.debug("Debug message")
logging.info("Information message")
logging.warning("Warning message")
logging.error("Error occurred")
logging.critical("Critical issue")
βββββββββββββββββββ
π Logging Levels
DEBUG β Detailed information
INFO β General program events
WARNING β Something unexpected
ERROR β Program error
CRITICAL β Serious failure
βββββββββββββββββββ
π Logging to a File
import logging
logging.basicConfig( filename="app.log", level=logging.INFO )
logging.info("Application started")
This creates a log file automatically.
βββββββββββββββββββ
β° Logging with Time Format
import logging
logging.basicConfig( filename="app.log", level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s" )
logging.info("Program started")
Example output:
2026-03-16 21:45:22 - INFO - Program started
βββββββββββββββββββ
π§ Why Logging is Important?
β Debugging large programs
β Monitoring applications
β Tracking errors in production
β Maintaining software systems
βββββββββββββββββββ
π Practice Tasks β Day 50
β Use logging instead of print
β Create log file
β Log errors and warnings
β Add time format
βββββββββββββββββββ
π― Day 50 Goal
β Understand logging system
β Track application events
β Improve debugging skills
βββββββββββββββββββ
π Next Topic β Day 51
π₯ Command Line Arguments in Python
β¨ Stay Connected | Keep Coding
π TechByWebCoder
β¨ Topic: Logging in Python
βββββββββββββββββββ
π What is Logging?
Logging is used to record events that happen while a program runs.
Instead of using print() everywhere, developers use logging to track:
β Errors
β Warnings
β Debug information
β Application activity
βββββββββββββββββββ
π¦ Logging Module
Python provides a built-in module:
import logging
βββββββββββββββββββ
πΉ Basic Logging Example
import logging
logging.basicConfig(level=logging.DEBUG)
logging.debug("Debug message")
logging.info("Information message")
logging.warning("Warning message")
logging.error("Error occurred")
logging.critical("Critical issue")
βββββββββββββββββββ
π Logging Levels
DEBUG β Detailed information
INFO β General program events
WARNING β Something unexpected
ERROR β Program error
CRITICAL β Serious failure
βββββββββββββββββββ
π Logging to a File
import logging
logging.basicConfig( filename="app.log", level=logging.INFO )
logging.info("Application started")
This creates a log file automatically.
βββββββββββββββββββ
β° Logging with Time Format
import logging
logging.basicConfig( filename="app.log", level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s" )
logging.info("Program started")
Example output:
2026-03-16 21:45:22 - INFO - Program started
βββββββββββββββββββ
π§ Why Logging is Important?
β Debugging large programs
β Monitoring applications
β Tracking errors in production
β Maintaining software systems
βββββββββββββββββββ
π Practice Tasks β Day 50
β Use logging instead of print
β Create log file
β Log errors and warnings
β Add time format
βββββββββββββββββββ
π― Day 50 Goal
β Understand logging system
β Track application events
β Improve debugging skills
βββββββββββββββββββ
π Next Topic β Day 51
π₯ Command Line Arguments in Python
β¨ Stay Connected | Keep Coding
π TechByWebCoder
π PYTHON β DAY 51 STUDY MATERIAL
β¨ Topic: Command Line Arguments in Python
ββββββββββββββββββ
π What are Command Line Arguments?
Command line arguments allow you to pass inputs to a Python program when running it from the terminal.
Example:
python script.py Soham
Here Soham is a command line argument.
βββββββββββββββββββ
π¦ Using sys Module
Python provides a built-in module:
import sys
This module allows access to command line arguments.
βββββββββββββββββββ
πΉ Basic Example
import sys
print(sys.argv)
Output example:
['script.py', 'Soham']
Explanation:
sys.argv[0] β script name
sys.argv[1] β first argument
βββββββββββββββββββ
πΉ Using Argument in Program
import sys
name = sys.argv[1]
print("Hello", name)
Run command:
python script.py Soham
Output:
Hello Soham
βββββββββββββββββββ
πΉ Multiple Arguments
import sys
a = int(sys.argv[1])
b = int(sys.argv[2])
print("Sum:", a + b)
Run:
python script.py 10 20
Output:
Sum: 30
βββββββββββββββββββ
β Handling Missing Arguments
import sys
if len(sys.argv) < 2:
print("Please provide an argument")
else:
print("Argument:", sys.argv[1])
βββββββββββββββββββ
π§ Where Command Line Arguments Are Used?
β Automation scripts
β DevOps tools
β System utilities
β Data processing scripts
βββββββββββββββββββ
π Practice Tasks β Day 51
β Print command line arguments
β Create greeting script
β Add two numbers using arguments
β Handle missing arguments
βββββββββββββββββββ
π― Day 51 Goal
β Understand command line inputs
β Use sys.argv
β Build simple CLI tools
βββββββββββββββββββ
π Next Topic β Day 52
π₯ Introduction to argparse (Professional CLI Tools)
β¨ Stay Connected | Keep Coding
π TechByWebCoder
β¨ Topic: Command Line Arguments in Python
ββββββββββββββββββ
π What are Command Line Arguments?
Command line arguments allow you to pass inputs to a Python program when running it from the terminal.
Example:
python script.py Soham
Here Soham is a command line argument.
βββββββββββββββββββ
π¦ Using sys Module
Python provides a built-in module:
import sys
This module allows access to command line arguments.
βββββββββββββββββββ
πΉ Basic Example
import sys
print(sys.argv)
Output example:
['script.py', 'Soham']
Explanation:
sys.argv[0] β script name
sys.argv[1] β first argument
βββββββββββββββββββ
πΉ Using Argument in Program
import sys
name = sys.argv[1]
print("Hello", name)
Run command:
python script.py Soham
Output:
Hello Soham
βββββββββββββββββββ
πΉ Multiple Arguments
import sys
a = int(sys.argv[1])
b = int(sys.argv[2])
print("Sum:", a + b)
Run:
python script.py 10 20
Output:
Sum: 30
βββββββββββββββββββ
β Handling Missing Arguments
import sys
if len(sys.argv) < 2:
print("Please provide an argument")
else:
print("Argument:", sys.argv[1])
βββββββββββββββββββ
π§ Where Command Line Arguments Are Used?
β Automation scripts
β DevOps tools
β System utilities
β Data processing scripts
βββββββββββββββββββ
π Practice Tasks β Day 51
β Print command line arguments
β Create greeting script
β Add two numbers using arguments
β Handle missing arguments
βββββββββββββββββββ
π― Day 51 Goal
β Understand command line inputs
β Use sys.argv
β Build simple CLI tools
βββββββββββββββββββ
π Next Topic β Day 52
π₯ Introduction to argparse (Professional CLI Tools)
β¨ Stay Connected | Keep Coding
π TechByWebCoder
π PYTHON β DAY 52 STUDY MATERIAL
β¨ Topic: argparse β Building Professional CLI Tools
βββββββββββββββββββ
π What is argparse?
argparse is Pythonβs standard library for building command-line interfaces (CLI).
It helps you:
β Parse command-line arguments
β Show help messages automatically
β Validate user input
β Build professional CLI tools
βββββββββββββββββββ
π¦ Importing argparse
import argparse
βββββββββββββββββββ
πΉ Basic Example
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("name")
args = parser.parse_args()
print("Hello", args.name)
Run command:
python script.py Soham
Output:
Hello Soham
βββββββββββββββββββ
πΉ Adding Optional Arguments
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--age", type=int)
args = parser.parse_args()
print("Age:", args.age)
Run command:
python script.py --age 20
βββββββββββββββββββ
πΉ Adding Help Description
parser = argparse.ArgumentParser( description="Simple CLI Program" )
Running this command shows help:
python script.py --help
It displays all arguments automatically π
βββββββββββββββββββ
πΉ Multiple Arguments Example
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("num1", type=int)
parser.add_argument("num2", type=int)
args = parser.parse_args()
print("Sum:", args.num1 + args.num2)
Run command:
python script.py 10 5
Output:
Sum: 15
βββββββββββββββββββ
π§ Where argparse is Used?
β DevOps scripts
β Data processing tools
β Automation utilities
β Command-line applications
βββββββββββββββββββ
π Practice Tasks β Day 52
β Create CLI greeting tool
β Add optional argument
β Create CLI calculator
β Use help command
βββββββββββββββββββ
π― Day 52 Goal
β Understand argparse module
β Build professional CLI programs
β Improve command-line scripting skills
βββββββββββββββββββ
π Next Topic β Day 53
π₯ Environment Variables in Python
β¨ Stay Connected | Keep Coding
π TechByWebCoder
β¨ Topic: argparse β Building Professional CLI Tools
βββββββββββββββββββ
π What is argparse?
argparse is Pythonβs standard library for building command-line interfaces (CLI).
It helps you:
β Parse command-line arguments
β Show help messages automatically
β Validate user input
β Build professional CLI tools
βββββββββββββββββββ
π¦ Importing argparse
import argparse
βββββββββββββββββββ
πΉ Basic Example
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("name")
args = parser.parse_args()
print("Hello", args.name)
Run command:
python script.py Soham
Output:
Hello Soham
βββββββββββββββββββ
πΉ Adding Optional Arguments
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--age", type=int)
args = parser.parse_args()
print("Age:", args.age)
Run command:
python script.py --age 20
βββββββββββββββββββ
πΉ Adding Help Description
parser = argparse.ArgumentParser( description="Simple CLI Program" )
Running this command shows help:
python script.py --help
It displays all arguments automatically π
βββββββββββββββββββ
πΉ Multiple Arguments Example
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("num1", type=int)
parser.add_argument("num2", type=int)
args = parser.parse_args()
print("Sum:", args.num1 + args.num2)
Run command:
python script.py 10 5
Output:
Sum: 15
βββββββββββββββββββ
π§ Where argparse is Used?
β DevOps scripts
β Data processing tools
β Automation utilities
β Command-line applications
βββββββββββββββββββ
π Practice Tasks β Day 52
β Create CLI greeting tool
β Add optional argument
β Create CLI calculator
β Use help command
βββββββββββββββββββ
π― Day 52 Goal
β Understand argparse module
β Build professional CLI programs
β Improve command-line scripting skills
βββββββββββββββββββ
π Next Topic β Day 53
π₯ Environment Variables in Python
β¨ Stay Connected | Keep Coding
π TechByWebCoder
π Top 2 Full Stack Python Django Project with MySQL Database
We offer a complete collection of 2 modern Full Stack Python Django web applications developed using Django, HTML, CSS, JavaScript, and MySQL/SQLite database connectivity. These projects are perfect for computer science students, final-year projects, freelancers, and portfolio building.
π₯οΈ Code: https://rzp.io/rzp/pydjango-1
πΌοΈ Output Preview: https://youtu.be/234fQQRKy7E
π Included Projects
1. AI Resume Analyzer & Job Matcher
2. Smart Study Planner with AI
π¦ What You Will Get (For Each Project):
β’ Full Python Source Code (Python Djnago+ MySQL)
β’ MySQL Database File (.sql)
β’ Output Screenshots / UI Preview
β’ Project Documentation (Detailed Report)
β’ PowerPoint Presentation (PPT)
β’ User Manual (Step-by-Step Guide)
β’ README File (Installation + Setup Instructions)
β’ Well-Structured and Easy-to-Understand Code
Follow For More !
We offer a complete collection of 2 modern Full Stack Python Django web applications developed using Django, HTML, CSS, JavaScript, and MySQL/SQLite database connectivity. These projects are perfect for computer science students, final-year projects, freelancers, and portfolio building.
π₯οΈ Code: https://rzp.io/rzp/pydjango-1
πΌοΈ Output Preview: https://youtu.be/234fQQRKy7E
π Included Projects
1. AI Resume Analyzer & Job Matcher
2. Smart Study Planner with AI
π¦ What You Will Get (For Each Project):
β’ Full Python Source Code (Python Djnago+ MySQL)
β’ MySQL Database File (.sql)
β’ Output Screenshots / UI Preview
β’ Project Documentation (Detailed Report)
β’ PowerPoint Presentation (PPT)
β’ User Manual (Step-by-Step Guide)
β’ README File (Installation + Setup Instructions)
β’ Well-Structured and Easy-to-Understand Code
Follow For More !
π PYTHON β DAY 53 STUDY MATERIAL
β¨ Topic: Environment Variables in Python
βββββββββββββββββββ
π What are Environment Variables?
Environment variables are external values stored in the operating system that programs can access.
They are used to store:
β API keys
β Database credentials
β Configuration settings
β Secret tokens
This helps keep sensitive data secure.
βββββββββββββββββββ
π¦ Using os Module
Python provides the os module to access environment variables.
import os
βββββββββββββββββββ
πΉ Reading an Environment Variable
import os
api_key = os.getenv("API_KEY")
print(api_key)
If the variable exists β value is returned
If not β returns None
βββββββββββββββββββ
πΉ Setting Environment Variable (Temporarily)
Windows:
set API_KEY=12345
Mac/Linux:
export API_KEY=12345
Then run Python program.
βββββββββββββββββββ
πΉ Providing Default Value
import os
api_key = os.getenv("API_KEY", "DefaultKey")
print(api_key)
If variable is missing β DefaultKey will be used.
βββββββββββββββββββ
π Using .env Files (Best Practice)
Install library:
pip install python-dotenv
Example:
API_KEY=12345
DB_PASSWORD=secret
Python code:
from dotenv import load_dotenv
import os
load_dotenv()
print(os.getenv("API_KEY"))
βββββββββββββββββββ
π§ Why Environment Variables are Important?
β Secure application configuration
β Protect sensitive data
β Used in deployment & cloud platforms
βββββββββββββββββββ
π Practice Tasks β Day 53
β Create environment variable
β Read variable in Python
β Use default value
β Create .env file
βββββββββββββββββββ
π― Day 53 Goal
β Understand environment variables
β Protect sensitive information
β Manage application configuration
βββββββββββββββββββ
π Next Topic β Day 54
π₯ Introduction to REST API Development using Flask
β¨ Stay Connected | Keep Coding
π TechByWebCoder
β¨ Topic: Environment Variables in Python
βββββββββββββββββββ
π What are Environment Variables?
Environment variables are external values stored in the operating system that programs can access.
They are used to store:
β API keys
β Database credentials
β Configuration settings
β Secret tokens
This helps keep sensitive data secure.
βββββββββββββββββββ
π¦ Using os Module
Python provides the os module to access environment variables.
import os
βββββββββββββββββββ
πΉ Reading an Environment Variable
import os
api_key = os.getenv("API_KEY")
print(api_key)
If the variable exists β value is returned
If not β returns None
βββββββββββββββββββ
πΉ Setting Environment Variable (Temporarily)
Windows:
set API_KEY=12345
Mac/Linux:
export API_KEY=12345
Then run Python program.
βββββββββββββββββββ
πΉ Providing Default Value
import os
api_key = os.getenv("API_KEY", "DefaultKey")
print(api_key)
If variable is missing β DefaultKey will be used.
βββββββββββββββββββ
π Using .env Files (Best Practice)
Install library:
pip install python-dotenv
Example:
API_KEY=12345
DB_PASSWORD=secret
Python code:
from dotenv import load_dotenv
import os
load_dotenv()
print(os.getenv("API_KEY"))
βββββββββββββββββββ
π§ Why Environment Variables are Important?
β Secure application configuration
β Protect sensitive data
β Used in deployment & cloud platforms
βββββββββββββββββββ
π Practice Tasks β Day 53
β Create environment variable
β Read variable in Python
β Use default value
β Create .env file
βββββββββββββββββββ
π― Day 53 Goal
β Understand environment variables
β Protect sensitive information
β Manage application configuration
βββββββββββββββββββ
π Next Topic β Day 54
π₯ Introduction to REST API Development using Flask
β¨ Stay Connected | Keep Coding
π TechByWebCoder
π Top 2 Full Stack Python Django Project with MySQL Database
We offer a complete collection of 2 modern Full Stack Python Django web applications developed using Django, HTML, CSS, JavaScript, and MySQL/SQLite database connectivity. These projects are perfect for computer science students, final-year projects, freelancers, and portfolio building.
π₯οΈ Code: https://rzp.io/rzp/pydjango-2
πΌοΈ Output Preview: https://youtu.be/3OvYLoQS2jM
π Included Projects
1. Fake News Detection Platform
2. Online Code Judge System
π¦ What You Will Get (For Each Project):
β’ Full Python Source Code (Python Djnago+ MySQL)
β’ MySQL Database File (.sql)
β’ Output Screenshots / UI Preview
β’ Project Documentation (Detailed Report)
β’ PowerPoint Presentation (PPT)
β’ User Manual (Step-by-Step Guide)
β’ README File (Installation + Setup Instructions)
β’ Well-Structured and Easy-to-Understand Code
Follow For More !
We offer a complete collection of 2 modern Full Stack Python Django web applications developed using Django, HTML, CSS, JavaScript, and MySQL/SQLite database connectivity. These projects are perfect for computer science students, final-year projects, freelancers, and portfolio building.
π₯οΈ Code: https://rzp.io/rzp/pydjango-2
πΌοΈ Output Preview: https://youtu.be/3OvYLoQS2jM
π Included Projects
1. Fake News Detection Platform
2. Online Code Judge System
π¦ What You Will Get (For Each Project):
β’ Full Python Source Code (Python Djnago+ MySQL)
β’ MySQL Database File (.sql)
β’ Output Screenshots / UI Preview
β’ Project Documentation (Detailed Report)
β’ PowerPoint Presentation (PPT)
β’ User Manual (Step-by-Step Guide)
β’ README File (Installation + Setup Instructions)
β’ Well-Structured and Easy-to-Understand Code
Follow For More !
π PYTHON β DAY 54 STUDY MATERIAL
β¨ Topic: Introduction to REST API Development using Flask
βββββββββββββββββββ
π What is Flask?
Flask is a lightweight Python web framework used to build:
β Web applications
β REST APIs
β Backend services
It is simple, flexible, and widely used in Python backend development.
βββββββββββββββββββ
π¦ Install Flask
pip install flask
Import in Python:
from flask import Flask
βββββββββββββββββββ
π₯ Creating First Flask App
from flask import Flask
app = Flask(name)
@app.route("/")
def home():
return "Hello, Flask API!"
app.run(debug=True)
Run the program and open browser:
http://127.0.0.1:5000
βββββββββββββββββββ
π Creating API Endpoint
from flask import Flask, jsonify
app = Flask(name)
@app.route("/api")
def api():
data = {"message": "Hello API"}
return jsonify(data)
app.run(debug=True)
Output:
{ "message": "Hello API" }
βββββββββββββββββββ
πΉ Handling URL Parameters
@app.route("/user/")
def user(name):
return "Hello " + name
Example:
http://127.0.0.1:5000/user/Soham
Output:
Hello Soham
βββββββββββββββββββ
πΉ Handling JSON Request (POST)
from flask import request
@app.route("/data", methods=["POST"])
def receive():
data = request.json
return {"received": data}
βββββββββββββββββββ
π§ Where Flask APIs Are Used?
β Mobile app backends
β Web application backends
β AI model APIs
β Microservices architecture
βββββββββββββββββββ
π Practice Tasks β Day 54
β Install Flask
β Create simple API
β Return JSON response
β Use URL parameter
βββββββββββββββββββ
π― Day 54 Goal
β Understand Flask framework
β Create simple REST API
β Handle requests and responses
βββββββββββββββββββ
π Next Topic β Day 55
π₯ Connecting Flask with Database (SQLite)
β¨ Stay Connected | Keep Coding
π TechByWebCoder
β¨ Topic: Introduction to REST API Development using Flask
βββββββββββββββββββ
π What is Flask?
Flask is a lightweight Python web framework used to build:
β Web applications
β REST APIs
β Backend services
It is simple, flexible, and widely used in Python backend development.
βββββββββββββββββββ
π¦ Install Flask
pip install flask
Import in Python:
from flask import Flask
βββββββββββββββββββ
π₯ Creating First Flask App
from flask import Flask
app = Flask(name)
@app.route("/")
def home():
return "Hello, Flask API!"
app.run(debug=True)
Run the program and open browser:
http://127.0.0.1:5000
βββββββββββββββββββ
π Creating API Endpoint
from flask import Flask, jsonify
app = Flask(name)
@app.route("/api")
def api():
data = {"message": "Hello API"}
return jsonify(data)
app.run(debug=True)
Output:
{ "message": "Hello API" }
βββββββββββββββββββ
πΉ Handling URL Parameters
@app.route("/user/")
def user(name):
return "Hello " + name
Example:
http://127.0.0.1:5000/user/Soham
Output:
Hello Soham
βββββββββββββββββββ
πΉ Handling JSON Request (POST)
from flask import request
@app.route("/data", methods=["POST"])
def receive():
data = request.json
return {"received": data}
βββββββββββββββββββ
π§ Where Flask APIs Are Used?
β Mobile app backends
β Web application backends
β AI model APIs
β Microservices architecture
βββββββββββββββββββ
π Practice Tasks β Day 54
β Install Flask
β Create simple API
β Return JSON response
β Use URL parameter
βββββββββββββββββββ
π― Day 54 Goal
β Understand Flask framework
β Create simple REST API
β Handle requests and responses
βββββββββββββββββββ
π Next Topic β Day 55
π₯ Connecting Flask with Database (SQLite)
β¨ Stay Connected | Keep Coding
π TechByWebCoder
π PYTHON β DAY 55 STUDY MATERIAL
β¨ Topic: Connecting Flask with SQLite Database
βββββββββββββββββββ
π Goal
Build a simple Flask API that stores and retrieves data from SQLite database.
Concepts used:
β Flask API
β SQLite Database
β JSON responses
β CRUD operations
βββββββββββββββββββ
π¦ Import Required Modules
from flask import Flask, request, jsonify
import sqlite3
app = Flask(name)
βββββββββββββββββββ
π Create Database Connection
def get_db():
conn = sqlite3.connect("student.db")
conn.row_factory = sqlite3.Row
return conn
βββββββββββββββββββ
β API: Add Student
@app.route("/add", methods=["POST"])
def add_student():
data = request.json
conn = get_db()
conn.execute(
"INSERT INTO student(name,age) VALUES(?,?)",
(data["name"], data["age"])
)
conn.commit()
conn.close()
return {"message": "Student added"}
βββββββββββββββββββ
π API: Get All Students
@app.route("/students")
def get_students():
conn = get_db()
students = conn.execute(
"SELECT * FROM student"
).fetchall()
conn.close()
return jsonify([dict(row) for row in students])
βββββββββββββββββββ
π API: Get Student by ID
@app.route("/student/int:id")
def get_student(id):
conn = get_db()
student = conn.execute(
"SELECT * FROM student WHERE id=?",
(id,)
).fetchone()
conn.close()
return jsonify(dict(student))
βββββββββββββββββββ
π Run Flask Application
if name == "main":
app.run(debug=True)
βββββββββββββββββββ
π§ What You Learned Today
β Connect Flask with SQLite
β Create REST APIs with database
β Return JSON responses
βββββββββββββββββββ
π Practice Tasks β Day 55
β Create student API
β Insert student data
β Fetch all students
β Fetch student by ID
βββββββββββββββββββ
π― Day 55 Goal
β Build backend API with database
β Perform CRUD using Flask
β Understand backend architecture
βββββββββββββββββββ
π Next Topic β Day 56
π₯ Authentication System in Flask (Login API)
β¨ Stay Connected | Keep Coding
π TechByWebCoder
β¨ Topic: Connecting Flask with SQLite Database
βββββββββββββββββββ
π Goal
Build a simple Flask API that stores and retrieves data from SQLite database.
Concepts used:
β Flask API
β SQLite Database
β JSON responses
β CRUD operations
βββββββββββββββββββ
π¦ Import Required Modules
from flask import Flask, request, jsonify
import sqlite3
app = Flask(name)
βββββββββββββββββββ
π Create Database Connection
def get_db():
conn = sqlite3.connect("student.db")
conn.row_factory = sqlite3.Row
return conn
βββββββββββββββββββ
β API: Add Student
@app.route("/add", methods=["POST"])
def add_student():
data = request.json
conn = get_db()
conn.execute(
"INSERT INTO student(name,age) VALUES(?,?)",
(data["name"], data["age"])
)
conn.commit()
conn.close()
return {"message": "Student added"}
βββββββββββββββββββ
π API: Get All Students
@app.route("/students")
def get_students():
conn = get_db()
students = conn.execute(
"SELECT * FROM student"
).fetchall()
conn.close()
return jsonify([dict(row) for row in students])
βββββββββββββββββββ
π API: Get Student by ID
@app.route("/student/int:id")
def get_student(id):
conn = get_db()
student = conn.execute(
"SELECT * FROM student WHERE id=?",
(id,)
).fetchone()
conn.close()
return jsonify(dict(student))
βββββββββββββββββββ
π Run Flask Application
if name == "main":
app.run(debug=True)
βββββββββββββββββββ
π§ What You Learned Today
β Connect Flask with SQLite
β Create REST APIs with database
β Return JSON responses
βββββββββββββββββββ
π Practice Tasks β Day 55
β Create student API
β Insert student data
β Fetch all students
β Fetch student by ID
βββββββββββββββββββ
π― Day 55 Goal
β Build backend API with database
β Perform CRUD using Flask
β Understand backend architecture
βββββββββββββββββββ
π Next Topic β Day 56
π₯ Authentication System in Flask (Login API)
β¨ Stay Connected | Keep Coding
π TechByWebCoder