Skip to main content
In this lesson/article we take a focused tour of GitHub Copilot inside Visual Studio Code and use it to scaffold a small Python project that reads and prints CSV data. Along the way we’ll demonstrate how Copilot helps you:
  • Scaffold a Python app with an argument parser (argparse)
  • Create mock CSV data for quick testing
  • Suggest edits to fix runtime errors from tracebacks
  • Generate simple unit tests and test configuration
This walkthrough uses a workspace folder named csvreader.
GitHub Copilot speeds up routine tasks by generating boilerplate (project scaffolds, argument parsing, tests) and proposing fixes based on error output. Always review generated code for correctness and security — Copilot helps you iterate faster, not replace review.

Project scaffold and virtual environment

Quick steps to create the project directory and a Python virtual environment:
A minimal app.py example Copilot might generate:
Install any runtime dependencies as needed and run the script:
Quick reference — useful local commands:

Scaffolding a main script with argparse

Copilot (inline suggestions or Copilot Chat) can quickly scaffold a main.py using argparse so your script accepts a CSV file path. A typical skeleton looks like:
Save the file and run it to confirm the script executes. If you see “unrecognized arguments,” Copilot can suggest missing parser.add_argument(...) lines when you paste the traceback into Copilot Chat.

Creating a mock CSV file

For quick testing create a mock CSV file (e.g., data.csv) with columns: first name, last name, IP address, city, state. Copilot can generate this for you if asked.

Reading a CSV file (initial approach)

Copilot often suggests a minimal read_csv implementation using readlines():
Connect this to the argument parser and print the file contents:
Run the script:
If Copilot inserted the parser argument incorrectly (e.g., you get “unrecognized arguments”), paste the error message into Copilot Chat and accept the suggested parser.add_argument(...) edits directly in the editor.

Parsing fields and showing only first and last names

To print only first and last names and skip the header, update the loop to split lines and ignore the first row:
Running python main.py data.csv produces:
Callout: For production or complex CSVs prefer the standard library’s csv module, which handles quoting and embedded commas robustly.

Fixing errors with Copilot

A practical Copilot workflow:
  • Run the code and copy any traceback/trace output.
  • Paste the error into Copilot Chat.
  • Copilot will typically propose targeted fixes (e.g., add missing parser.add_argument, fix indexing issues, or handle file-not-found errors).
  • Review the proposed changes and apply them in your editor.
This iterative loop accelerates debugging while keeping you in control.

Generating tests

Copilot can scaffold tests and configure a test runner. In the demo, Copilot produced a test_main.py file using unittest style tests. You can convert these to pytest style if preferred. Example test_main.py:
Run the test suite:
Example pytest output when tests pass:
If you intentionally change expected values to force a failure, the pytest trace will show differing elements — Copilot can help interpret the output and suggest fixes or improved assertions.

Adding docstrings and comments

Copilot can generate docstrings and inline comments. Select a function and ask Copilot to document it — it will insert a docstring describing the function’s purpose, parameters, and return values. Use generated docs as a starting point and refine them to match your code’s intent.

Summary

GitHub Copilot in Visual Studio Code is handy for:
  • Scaffolding applications and argparse usage
  • Generating test scaffolding and basic unit tests
  • Producing mock data files for development and tests
  • Suggesting quick fixes based on error messages and tracebacks
  • Drafting comments and docstrings
Copilot accelerates routine development tasks, but always review generated code for correctness, performance, and security. For reliable CSV parsing in production, prefer the built-in csv module or a vetted third-party library. Next in the course: we’ll look at Cursor AI, an IDE built on Visual Studio Code.

Watch Video