Pair Programming: The Copilot βοΈπ€ β
Pair programming is when two developers work on one computer. One drives (types), the other navigates (thinks). With AI, you are always the Captain. The AI is your Copilot.
The Workflow: Loop of Interaction βΎοΈ β
1. The "Kickoff" β
Start by explaining the goal.
"We are going to build a CLI tool to resize images. Let's start by setting up the project structure."
2. The "Navigator" Mode (You Drive) β
You write the code, but you ask for specific help.
"I forgot the syntax for
argparse. Give me a snippet for a--widthargument."
3. The "Driver" Mode (AI Drives) β
You describe the logic, AI writes the block.
"Write a function
resize_image(path, width)usingPillow. It should save the new image with a_resizedsuffix."
Learning a Standard Library π β
You don't always need big external packages. Python has amazing built-in tools.
Scenario: You want to pick a random winner from a list.
Prompt:
"I have a list of names. How do I pick a random one using Python's built-in
randommodule? Show me a simple example."
Result:
import random
winner = random.choice(['Alice', 'Bob', 'Charlie'])
print(winner)Learning a New Library (External) π¦ β
Instead of reading 100 pages of docs, ask AI to teach you the basics.
Scenario: You want to analyze data but don't know pandas.
Prompt:
"I am a beginner in Python. I want to use
pandasto read a CSV and filter rows where 'age' > 30. Show me the code and explain it step-by-step."
Result:
df = pd.read_csv('data.csv')filtered_df = df[df['age'] > 30]- Explanation of what a "DataFrame" is.
The "Import Explainer" π¦ β
You often copy-paste code with top-level imports you don't recognize.
Prompt:
"What does
import sysandimport osdo in this script? Explain it simply. Why do I need them?"
Result:
os: Used to talk to the Operating System (folders, files).sys: Used to talk to the Python Interpreter (command line arguments, exit).
Refactoring Pattern: The "Dictionary Lookup" β
Beginners love if/elif chains. AI can teach you the "Lookup" pattern.
Original Code:
def get_fruit_color(fruit):
if fruit == "apple": return "red"
elif fruit == "banana": return "yellow"
elif fruit == "grape": return "purple"Prompt:
"Refactor this
if/elifchain to use a Python Dictionary lookup instead. It's cleaner."
Result:
def get_fruit_color(fruit):
colors = {
"apple": "red",
"banana": "yellow",
"grape": "purple"
}
return colors.get(fruit, "unknown")Pattern: The "Data Transformer" π β
Converting data types is a common task.
Scenario: You have a list of items and want to count them.
Prompt:
"I have a list
['apple', 'banana', 'apple']. Write code to convert this into a dictionary counting the frequency:{'apple': 2, 'banana': 1}. Use a simple loop."
Result:
counts = {}
for item in items:
if item in counts:
counts[item] += 1
else:
counts[item] = 1Example Project: Building a CLI Tool β
Let's build a real tool: A file organizer.
Step 1: The Plan
"I want a Python script that scans a directory and moves files into folders based on extension (e.g., .jpg -> Images/, .pdf -> Docs/). Give me a high-level plan."
Step 2: The Core Logic
"Write a function using
shutilandosto move a file to a destination folder. Handle the case where the folder doesn't exist."
Step 3: The Interface
"Now wrap this in an
argparseCLI so I can runpython organize.py --folder ./downloads."
The Resulting Script:
import os
import shutil
import argparse
def organize_files(folder_path):
# Define rules
extensions = {
"Images": [".jpg", ".png", ".gif"],
"Docs": [".pdf", ".txt", ".docx"],
"Archives": [".zip", ".tar"]
}
# Loop through files
for filename in os.listdir(folder_path):
file_path = os.path.join(folder_path, filename)
if os.path.isdir(file_path):
continue # Skip folders
# Move logic
for category, exts in extensions.items():
if filename.endswith(tuple(exts)):
# Create category folder if missing
category_path = os.path.join(folder_path, category)
os.makedirs(category_path, exist_ok=True)
# Move file
shutil.move(file_path, os.path.join(category_path, filename))
print(f"Moved {filename} to {category}/")
break
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--folder", required=True)
args = parser.parse_args()
organize_files(args.folder)The Mentor: Code Reviews π§ β
Before you commit code, ask AI to review it.
Prompt:
"Act as a Senior Python Developer. Review this code for:
- Security vulnerabilities.
- Logic errors.
- Variable naming. Be harsh but constructive."
The Navigator: Getting Unstuck π§ β
If you stare at a blank screen for 5 minutes, ask for directions.
Scenario: You want to use an API but the documentation is confusing.
Prompt:
"I am trying to use the Stripe API to create a customer. I am confused by the authentication. Give me a minimal working example of just the authentication part."
The "Context" Problem π§ β
The AI only knows what fits in its "Context Window".
- If you have 50 files, it might not know about file #51.
- Tip: When asking for help, paste the relevant code snippets, not the whole codebase.
Task: Build a Mini-Tool π¨ β
Task
Goal: Build a Python script that fetches the weather for a city using a public API (like OpenMeteo) and prints it.
- Plan: Ask AI for the API URL and
requestssyntax. - Code: Write the fetch function.
- Debug: Handle the
404 Not Founderror.
Setting Up the Environment ποΈ β
The hardest part for beginners is often just starting.
Prompt:
"I want to start a new Python project to scrape a website. Tell me the exact terminal commands to:
- Create a folder named
scraper_project.- Create a virtual environment (
venv) so I don't mess up my system.- Activate it.
- Install
requestsandbeautifulsoup4."
Why?: You don't need to memorize these commands. Let the AI be your cheat sheet.
The Terminal Translator π» β
Terminal errors are scary. "Exit code 1"? "Permission denied"?
Prompt:
"I tried to run
pip install pandasand got this error:error: externally-managed-environmentWhat does this mean and how do I fix it on a Mac?"
Result: It will explain you need to use a virtual environment or pipx.
Conclusion: You are still the Pilot π©ββοΈ β
AI makes you faster, not smarter.
- If you don't understand the code, you will be the one waking up at 3 AM to fix it.
- Use AI to learn, not just to output.
Related Topics π β
- Collaboration & Git: How to work with human partners and shared code.
- Python Setup: Get your environment ready for the code you create.