1. Introduction to scripting and automation
-
What is scripting?
-
Benefits of automation with Python.
-
Python's role in system administration, DevOps, web automation, and data processing.
-
Comparison of Python with other scripting languages (e.g., Bash, Perl).
2. Python fundamentals for scripting
-
Basic Syntax and Data Structures: Reviewing variables, data types (strings, numbers, booleans), lists, tuples, sets, and dictionaries.
-
Control Flow: Using conditional statements (if, elif, else) and loops (for, while) for logic and iteration.
-
Functions and Modules: Defining and using functions to organize code, creating and importing modules, and utilizing Python's standard library.
-
Exception Handling: Gracefully handling errors and unexpected events using try, except, and finally blocks.
-
File I/O: Reading from and writing to files, handling different file types (text, CSV, JSON), and managing file modes.
-
Command-Line Arguments: Accepting and parsing command-line arguments to make scripts flexible and reusable.
3. Working with the operating system and file system
-
os and shutil Modules: Interacting with the operating system, managing files and directories (creation, deletion, copying, moving), and working with environment variables.
-
subprocess Module: Running external commands and shell scripts from Python scripts.
-
Path Management with pathlib: Using the pathlib module for object-oriented file system path manipulation.
-
File Compression and Archiving: Using Python libraries to compress and decompress files.
4. Text processing and regular expressions (RegEx)
-
String Manipulation: Working with string methods for searching, replacing, and formatting text.
-
Regular Expressions: Mastering RegEx syntax and using the re module for pattern matching and extraction from text.
-
Use Cases: Email validation, phone number extraction, password strength validation, and parsing log files or web content.
5. Web interaction and automation
-
Web Scraping with BeautifulSoup: Extracting data from websites by parsing HTML and XML content.
-
HTTP Requests with requests: Making HTTP requests to interact with web services and APIs.
-
Web Automation with Selenium (Optional): Automating browser tasks like navigating websites, filling forms, and clicking elements.
-
API Automation: Using Python to interact with various APIs for data retrieval and task automation.
6. System monitoring and administration
-
psutil Module: Retrieving system information, monitoring CPU, memory, disk usage, and managing processes.
-
Task Scheduling: Using libraries or system tools (e.g., cron on Linux, Task Scheduler on Windows) to schedule scripts for execution at specific times.
-
Logging: Implementing logging to track script execution, record events, and debug issues.
7. Building command-line interfaces (CLIs)
-
argparse Module: Creating sophisticated command-line interfaces with arguments, options, and subcommands.
-
Click or Typer Libraries (Optional): Building user-friendly CLIs with features like automatic help generation, input validation, and command chaining.
8. Advanced scripting techniques and best practices
-
Version Control with Git: Using Git for tracking code changes, collaborating with others, and managing script versions.
-
Debugging and Testing: Techniques for debugging Python scripts, using debugging tools, writing unit tests, and ensuring script reliability.
-
Security Best Practices: Securing scripts, handling sensitive information, and implementing safe coding practices.
-
Code Structure and Organization: Organizing scripts into functions, classes, and modules for better maintainability and reusability.
-
Virtual Environments: Managing dependencies and creating isolated environments for projects.