The Automation Mindset

Decide what to automate — and how to do it safely

Intermediate 9 min

In this lesson

Automating a task with Python means writing a small script that does repetitive work for you. Before writing one, it pays to think clearly about what is worth automating and how to do it without causing damage. By the end you’ll frame any chore as inputs, process, and outputs, and you’ll know why every file-changing script should offer a dry run first.

Explain it like I’m 5

Automation is teaching the computer a chore so you don’t repeat the same careful steps by hand. A dry run is the computer telling you what it would do — before it actually does anything.

What automation actually is

Automation means writing a script that does a repetitive, rule-based task for you. The best candidates are chores you do often, that follow clear rules, and that are tedious or error-prone by hand — renaming a batch of photos, cleaning a CSV, building a weekly report. A one-off task you’ll never repeat usually isn’t worth scripting.

Example
# The same chore by hand, then handed to a loop
files = ["report1.txt", "report2.txt", "report3.txt"]
for name in files:
    print("Processing", name)
Output
Processing report1.txt
Processing report2.txt
Processing report3.txt
A loop does the repetitive part so you don't.

Inputs, process, outputs

Every useful automation fits one frame: it takes some inputs, runs a process, and produces outputs. Naming those three parts before you code keeps a script focused and makes it far easier to test — the process is usually a plain function you can check on its own.

Example
def clean_names(raw):
    return [name.strip().title() for name in raw]

raw = [" ada ", "BO", "cy  "]
print(clean_names(raw))
Output
['Ada', 'Bo', 'Cy']
Input: messy names. Process: clean each. Output: tidy list.

Safety first: dry-run before you touch anything

The moment a script changes real files, a bug can do real damage. The fix is a dry run: instead of acting, the script prints what it would do. You read the plan, confirm it’s right, and only then run it for real. Pair that with a backup and you can automate file changes without fear.

Finish dry_run so it returns a list of strings like "would delete old_1.log" for each file — it must not actually delete anything.

def dry_run(files):
    plan = []
    for name in files:
        pass  # TODO: append a "would delete <name>" line
    return plan

print(dry_run(["old_1.log", "old_2.log"]))

Common mistake: Automating a process you don’t fully understand yet

Why it happens:

It’s tempting to script a chore before you’ve done it carefully enough by hand to know all the edge cases.

How to fix it:

Do the task manually a few times first and write down the exact rules. Only automate once the process is clear — a script just applies your rules faster, including the wrong ones.

Common mistake: Changing real files with no backup

Why it happens:

Early scripts feel small and safe, so it’s easy to point one at important files and run it.

How to fix it:

Back up the data first and test on a copy. A five-second backup can save hours of recovery.

Common mistake: Skipping the dry run because “it’ll probably be fine”

Why it happens:

Adding a preview mode feels like extra work when you’re sure the script is right.

How to fix it:

Build dry-run mode in from the start. Printing the plan costs almost nothing and catches the mistakes you were sure you hadn’t made.

What makes a task a good candidate for automation?

What does a dry run do?

Before a script changes real files, what should you always have?

Mini exercise (medium)

Write automation_plan(tasks) that takes a list of dicts, each with a name and the minutes spent on it per week, and returns the names of the tasks taking 30 or more minutes a week — the ones worth automating — as a list.

Do it here. Finish the code below and press Run to try your answer right in the browser — no setup needed.

def automation_plan(tasks):
    # return the names of tasks taking 30 or more minutes per week
    return []

tasks = [
    {"name": "rename photos", "minutes": 45},
    {"name": "reply to one email", "minutes": 5},
    {"name": "build weekly report", "minutes": 60},
]
print(automation_plan(tasks))

What to learn next

You learned what makes a task worth automating — repetitive, rule-based, and frequent — and the inputs→process→outputs frame that keeps a script focused. Most importantly you saw why a dry run and a backup come before any file-changing code. You wrote automation_plan() to pick the chores worth the effort.

The first real tool to build is one that takes its inputs from the command line. Command-Line Scripts with argparse turns a hardcoded script into a proper CLI with arguments, flags, and automatic help. When you’re ready, continue to the next lesson.