This lesson is being piloted (Beta version)

Intermediate Programming with Python

This lesson is intended to follow on from our Introduction to Python lesson. It is designed to be used in both Data Carpentry and Software Carpentry workshops. This lesson assumes that you will be working from the command-line with Python files and the Python interpreter. The exercises could be completed in other environments such as Jupyter or an IDE, but this may require some small adaptations to the exercises.

Why Python 3?

Please note that this lesson uses Python 3 rather than Python 2. Support for Python 2 is due to end in 2020, and users are strongly urged to move to Python 3 as soon as possible. Given this, it makes sense that new users should start with Python 3. As an added bonus, this allows us to make use of some new features of Python 3.

Prerequisites

  1. Learners need to have a basic familiarity with the command line. Specifically, you need to understand:
    1. what files and directories are,
    2. what a working directory is,
    3. how to edit a text file,
    4. how to start a Python interpreter,
    5. and how to execute Python files.
  2. Learners must install Python before the class starts. The Anaconda distribution is a free distribution that provides a consistent set of scientific Python libraries for Windows, Linux, and Mac. We recommend you use Anaconda for this course, however any Python 3 will work.

  3. Learners must download the data before class starts. Please download and unzip the file intermediate_python_data.zip.

    Please see the setup instructions for details.

Schedule

Setup Download files required for the lesson
00:00 1. Modules How do I use code defined in other files or libraries?
What does the import statement do?
What are the effects of the common import variations?
00:50 2. Working with Files How do I open a file in Python?
How do I access the data or text inside an open file?
01:40 3. file processing
01:40 4. Creating and Running Python Scripts How can I run Python scripts and see results from them?
How do you write comments?
02:05 5. Getting arguments from the command-line Why are command-line arguments useful?
How can I add command-line arguments to my programs?
03:15 6. What's in a __name__? How do modules know when they are executing as a program, or being imported?
What does if __name__ == "__main__" do?
03:35 7. Final practical: How Many Articles Reference that they use R and/or Python? Can I write a command line Python progam using ArgParse?
03:35 Finish

The actual schedule may vary slightly depending on the topics and exercises chosen by the instructor.