Skip to main content
In this article, we explore GitHub Copilot—a powerful extension for Visual Studio Code—that assists you in developing a small CSV Reader application using Python. We cover setting up your project environment, scaffolding the application, reading and processing a CSV file, and even generating unit tests. GitHub Copilot helps both beginners and seasoned developers write less repetitive code and focus on solving problems.

Getting Started

GitHub Copilot provides intelligent code suggestions and generates boilerplate code to speed up development. To begin, install the GitHub Copilot extension in Visual Studio Code. Once installed, you will notice a “ready” status in the lower right-hand corner along with an integrated chat interface for code assistance. For example, if you ask, “How do I create a new Python app?” Copilot might suggest these steps:
You can activate Copilot’s inline help by pressing Command+I (or Control+I on Windows/Linux) and entering your prompt. Experimenting in the terminal is highly encouraged!

Creating a Python Virtual Environment and Application File

Open your terminal in Visual Studio Code and create your project directory with a dedicated virtual environment:
Next, create your main Python file:
As you start writing code in main.py, GitHub Copilot will offer contextual suggestions and help scaffold the basic structure of your application.

Building the CSV Reader Application

GitHub Copilot might initially scaffold a simple Python application that prints a greeting. For example:
After confirming that the base application works (by running python main.py), you can extend it to read a CSV file.

Creating a Sample CSV File

Create a CSV file named data.csv with the following sample data:

Reading the CSV File

Enhance your Python application by adding a function to read the CSV file. The following example, suggested by GitHub Copilot, demonstrates how to do this:
Execute the application using the command below:
This command displays the contents of the CSV file in your terminal.

Processing CSV Data

To improve the output, the application can be modified to display only the first and last names from each record (excluding the header). Update your code as follows:
When you run the code, your terminal output should display:

Debugging and Enhancing with Copilot

If you encounter errors such as an undefined attribute (e.g., “AttributeError: ‘Namespace’ object has no attribute ‘csv_file’”), GitHub Copilot can help diagnose and fix these issues by suggesting the correct argument definitions.
Simply add the missing argument definition, and Copilot will adjust the code accordingly.

Generating Unit Tests

GitHub Copilot can also assist by generating unit tests for your code. The following is an example test file (test_main.py) for the read_csv function:
To run the tests, execute:
A successful test run will confirm that all tests have passed.

Conclusion

In this article, we demonstrated how GitHub Copilot can streamline your development process by helping you: • Scaffold a new Python application
• Set up and work within a virtual environment
• Read and process CSV file data effectively
• Troubleshoot errors with contextual code suggestions
• Generate boilerplate unit tests automatically
GitHub Copilot enhances productivity for both beginners and experienced developers by saving time on repetitive code tasks. Next, explore Cursor—a fork of Visual Studio Code offering a uniquely enhanced IDE experience. Happy coding!

Watch Video