Skip to content

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 --width argument."

3. The "Driver" Mode (AI Drives) ​

You describe the logic, AI writes the block.

"Write a function resize_image(path, width) using Pillow. It should save the new image with a _resized suffix."

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 random module? Show me a simple example."

Result:

python
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 pandas to read a CSV and filter rows where 'age' > 30. Show me the code and explain it step-by-step."

Result:

  1. df = pd.read_csv('data.csv')
  2. filtered_df = df[df['age'] > 30]
  3. 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 sys and import os do 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:

python
def get_fruit_color(fruit):
    if fruit == "apple": return "red"
    elif fruit == "banana": return "yellow"
    elif fruit == "grape": return "purple"

Prompt:

"Refactor this if/elif chain to use a Python Dictionary lookup instead. It's cleaner."

Result:

python
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:

python
counts = {}
for item in items:
    if item in counts:
        counts[item] += 1
    else:
        counts[item] = 1

Example 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 shutil and os to 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 argparse CLI so I can run python organize.py --folder ./downloads."

The Resulting Script:

python
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:

  1. Security vulnerabilities.
  2. Logic errors.
  3. 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.

  1. Plan: Ask AI for the API URL and requests syntax.
  2. Code: Write the fetch function.
  3. Debug: Handle the 404 Not Found error.

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:

  1. Create a folder named scraper_project.
  2. Create a virtual environment (venv) so I don't mess up my system.
  3. Activate it.
  4. Install requests and beautifulsoup4."

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 pandas and got this error: error: externally-managed-environment What 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.