0% found this document useful (0 votes)
14 views10 pages

Python File Automation and Email Tasks

The document discusses Python's capabilities for file automation, including the use of built-in modules like os, shutil, and pathlib for file management tasks. It also covers the smtplib library for sending emails via SMTP and outlines methods for scheduling tasks in Python using the time module, schedule library, and APScheduler. Additionally, it highlights important libraries for data handling and visualization, such as NumPy, Pandas, matplotlib, and Seaborn.

Uploaded by

mohammedzaid0505
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views10 pages

Python File Automation and Email Tasks

The document discusses Python's capabilities for file automation, including the use of built-in modules like os, shutil, and pathlib for file management tasks. It also covers the smtplib library for sending emails via SMTP and outlines methods for scheduling tasks in Python using the time module, schedule library, and APScheduler. Additionally, it highlights important libraries for data handling and visualization, such as NumPy, Pandas, matplotlib, and Seaborn.

Uploaded by

mohammedzaid0505
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

Module 5

By Degala Sri Devi,135972


File Automation
 Python is a powerful tool for automating various file-related tasks,
streamlining workflows and reducing manual effort. This is achieved
through its built-in modules and external libraries that provide
functionalities for interacting with the operating system and handling
files and directories.
 File automation means using Python scripts to automatically handle
repetitive file-related tasks, such as:
 Creating, renaming, deleting, or moving files/folders
 Sorting files by type, date, or size
 Reading/writing files (text, CSV, Excel, JSON, etc.)
 Backing up or organizing files
 Extracting or combining data from multiple files
Important modules and libraries
 os module:
 This module provides a way of using operating system-dependent
functionality. It allows you to:List directory contents ([Link]()).
 Create and remove directories(folder)([Link](), [Link]()).
 Change the current working directory ([Link]()).
 Get file and directory paths ([Link]).
 Rename files and directories ([Link]()).
 shutil module:
 This module offers higher-level file operations, including:
 Copying files and directories ([Link](), [Link]()).
 Moving files and directories ([Link]()).
 Deleting entire directory trees ([Link]())
Contd…

 pathlib module:
 This module provides an object-oriented approach to file system
paths, making path manipulation more intuitive and readable.
 glob module:
 This module finds all the pathnames matching a specified pattern
according to the rules used by the Unix shell.
smtplib
 SMTP stands for Simple Mail Transfer Protocol.
It’s the standard protocol used on the Internet to send emails from
one server or client to another.
 Think of SMTP as the “postman” of the email world:
 It takes your email (message, subject, recipient address),
 Connects to the mail server (like Gmail, Outlook, Yahoo),
 And delivers your message to the receiver’s mail server.
 smtplib is a built-in Python library (no need to install anything).
 It allows you to create a connection between your Python program
and an SMTP server (like Gmail’s).
 Once connected, you can use it to send emails programmatically.
Contd…
 s = [Link]('[Link]', 587)
587 is the port number used for TLS (Transport Layer Security)
[Link] means the connection will be secure after calling starttls()
 For security reasons, we put the SMTP connection in TLS
mode. Transport Layer Security encrypts all the SMTP commands.
 import smtplib
 s = [Link]('[Link]', 587)
 [Link]()
 [Link]('youremail@[Link]', 'your_app_password')
 [Link]('youremail@[Link]', 'receiver@[Link]', 'Hello from
Python!')
 [Link]()
Scheduling tasks
 Task scheduling involves automating processes by defining tasks to
be executed at predetermined times or intervals.
 Task scheduling means executing a particular piece of code at a
specific time, or repeatedly at regular intervals — without
manual intervention.
 Python Ways to Schedule Tasks:
Types:
 1.) Using the time Module (Basic Scheduling):This is useful for simple
loop-based timing. This runs indefinitely until you stop it
Good for short background tasks — not for fixed times.
 2.) Using the schedule Library (Easiest Way):it mainly used for
scheduling the tasks.
[Link](5).[Link](job) → schedules the function.
run_pending() → checks whether any job is due to run
[Link](1) → prevents excessive CPU usage
 3.) Using APScheduler (Advanced Python Scheduler):Best for
complex, production-level jobs (e.g., web apps, background
services).
 We use BlockingScheduler means that once you start it, it will block
the rest of your program and keep running until you stop [Link]’s useful
for standalone scripts that should keep running indefinitely.
Python Important library’s

 NumPy is a library for working with numbers in efficient ways,


especially large arrays and matrices of data. It makes mathematical
operations on whole arrays fast and easy, making it the building
block for scientific computing in Python.
 Pandas is one of the most powerful Python libraries for data
handling, analysis, and cleaning.
Think of it like Excel inside Python — you can create tables, filter
rows, perform calculations, and analyze data efficiently
 matplotlib is a library for creating visualizations and graphs from
data. It helps you plot charts, histograms, line graphs, and other
types of plots to understand better.
Advanced visualization
 Seaborn is a high-level visualization library built on top of Matplotlib.
It makes it easier to create attractive and informative statistical
graphics with just a few lines of code.
 KDE = Kernel Density Estimate. KDE is a smooth curve that shows
the shape of a data distribution — like a smoothed version of a
histogram.
 KDE is used to understand data distribution shape (normal, skewed,
bimodal, etc.)
 What is correlation?
 Correlation measures the linear relationship between two numeric
variables.
 It gives values between -1 and +1:
 +1 → perfect positive correlation (as one increases, the other increases)
 -1 → perfect negative correlation (as one increases, the other decreases)
 0 → no linear relationship

You might also like