↓ Skip to main content

Efficient Python: TDD tests, Git, and factorial solved in one line

·279 words·2 mins·
 Author
Author
Francisco Bustamante
Chemist, data scientist and Python programmer.
Managing a Small Python Project - This article is part of a series.
Part 1: This Article

In this video (in Portuguese) I show how to structure a small Python project with the help of a very simple exercise. I present the steps to set up whatever editor or IDE you use, how to work with version control, in this case Git, and how to develop with tests (TDD, Test Driven Development).

When we are starting to learn Python, or any other programming language, it is very common to use a book, a reference website, or some other kind of material. And these materials usually have exercises to practice. However, there is rarely any instruction on how to structure your study environment in terms of code organization or configuring your editor or IDE.

Here, I use a very simple exercise, computing the factorial of a number, taken from the QuantEcon website, to show how to be more efficient in your studies and, on top of that, learn important concepts such as versioning with Git and test-driven development.

The links to websites and other materials mentioned in the video are right after the video player:

Summary of the steps:

  1. Organize a folder for the project
  2. The .gitignore file
  3. Initialize a Git repository
  4. Select the virtual environment (or create one for the project)
    • select the interpreter
    • install, if necessary, packages for the project
  5. Write tests and work on making them pass
  6. Make commits at relevant points of the project
  7. Work with branches when relevant, always keeping a presentable and working version on master

Repository with the code.

Basic Python course on the QuantEcon website.

Article here on the site about the Anaconda project.

Article here on the site about virtual environments.

Article here on the site about IPython.

Managing a Small Python Project - This article is part of a series.
Part 1: This Article

Related