Skip to content

Learning Python

petermr edited this page Dec 9, 2020 · 1 revision

Many of us are newcomers to Python. This wiki is for us to learn. To try to come up with solutions, and see if they work. Let's not "give the answer" from those who are expert. Let's see how we learn from books, questions, online tutorials, etc.

#How we learn

We learn in different ways. When I was running a course in bioinformatics in Birkbeck (London) 20 years ago I came up with the following analysis of how people learn programming:

chalk and talk

The lecturer tells the class the material and the students write it down.

Instructional book

"Learn X in Y days", "Z for dummies" ... These are usually self-paced.

Reading examples

Go out on the web and find examples of code that other people have written. This can be good if the code is good and terrible if it isn't. See is the code works. Modify it to do something different.

Personal project

"I want to build something that works!" "I like experimenting". Or a project that's handed out in a class.

Group project

Work together to create communal code. The advantages are that people can be helped by other people who understand the learning difficulties and tricks. Disadvantage is that some people don't engage and so don't learn.

Reference books and language specification

Yes, there are people who learn by reading formal documents

Group project

We are going to learn Python by working in small groups on relevant projects. In all of these we are going to be requirements-driven, and unit-test-driven We currently have three projects- people have been tentatively assigned

dictionary editor

dictionary-based search

open plants

Tools

UnitTests

We are going to need a UnitTest Harness, using Python unittest. This is something that the experienced Pythonistas can start on. The Python docs are good and stable. We need a recipe for our tests that everyone can use (only the experts have to know how to set up a test).

creating the tests

This is a learnt skill. A good test suite will think of all the desired outcomes AND all the undesired outcomes. We have to think of all the things that can go right, but also the things that can go wrong. For example, if we have a plantDict.removeMarchantia)` we need to:

  • test that plantDict has one less entry and no longer contains Marchantia
  • test that all the other entries are still there
  • test that the result is still a valid dictionary

... and several more

But we also need to test for probable error (exceptions):

  • what if the dictionary doesn't contain Marchantia at the start? Do we continue silently? Or return a value
  • what if the Marchantia argument is None? (It happens!)
  • what if plantDict isn't valid?

... and several more

Clone this wiki locally