Today’s goal is to improve and refine your existing Python scripts using better structure and basic error handling.
You will take any one script from:
- Day 01 (System Health Script), or
- Day 02 (API & JSON Script)
And enhance it by:
- Organizing the code into functions
- Adding basic exception handling (
try / except) - Improving variable names and readability
- Ensuring the script does not crash on common errors
This task focuses on writing cleaner and safer Python code, which is critical for DevOps automation.
- One improved Python script
- Script should:
- Run without crashing
- Handle at least one error gracefully
- Output should be visible in terminal
- Use:
try / exceptfor error handling- Functions to separate logic
- Example errors to handle:
- Invalid user input
- API request failure
- File not found
- Follow basic Python coding standards (PEP8)
- Do not rewrite everything from scratch
- Focus on improving existing code
-
Python exception handling:
https://docs.python.org/3/tutorial/errors.html -
PEP8 – Python Style Guide (must read):
https://peps.python.org/pep-0008/ -
Python Best Practices (read selectively):
https://docs.python-guide.org/writing/style/ -
Refactoring basics (from live class)
-
Your Day 01 / Day 02 scripts
In real-world DevOps:
- Scripts run in production
- Failures are common (network, permissions, input errors)
- Code is often read and modified by others
Following PEP8 and best practices makes your automation:
- Easier to debug
- Easier to maintain
- Safer to run in production environments
- Update your existing scripts from
day-01andday-02and update it inside theday-03folder - Ensure the script runs successfully
- Commit and push your changes to your fork
Share your progress on LinkedIn:
- Post a small code snippet showing improved structure or error handling
- Mention how you applied PEP8 or best practices
- Write 2–3 lines on what you learned today
Optional:
- Tag TrainWithShubham or Shubham Londhe
- Use hashtags:
#PythonForDevOps #TrainWithShubham #DevOpsKaJosh(Helps me to filter post and Like/ Comment / Repost / engage)
Happy Learning
TrainWithShubham