swcarpentry / python-novice-gapminder

Plotting and Programming in Python
http://swcarpentry.github.io/python-novice-gapminder/
Other
166 stars 431 forks source link

Suggestion: introduce getcwd and listdir, and remove lesson content about Markdown #554

Open srtee opened 3 years ago

srtee commented 3 years ago

I have helped in a few courses run based on the Gapminder material, and in common with Issue #528, getting to the correct directory and accessing the files is a common source of grief. My suggestion would be:

  1. put in material in Episode 1 covering working directories in Python, and
  2. remove the material on Markdown from the same Episode.

The high-level argument for (2) is that Markdown is not mentioned throughout the rest of the course material -- furthermore, it is more a feature of Jupyter and other notebook IDEs rather than Python itself. A Python learner will often be stumped by "File not found"-type errors from not knowing how to navigate directory structures in-script (including in the course itself!), far more than wanting to put a notebook cell into Markdown and not knowing how to.

This would entail the following changes:

Objectives

Key Points

and replacing the Markdown content with some exposition around an exercise to open a new Python cell, run the following commands, and describe the results:

from os import getcwd, listdir print(getcwd()) print(getcwd()+'/data')

print(listdir('data')) print(listdir(getcwd() + '/data'))

Learners can be reassured that they will understand the syntax a lot more later on in the course, but for now, they are just learning how to check their working directory and make sure they have their Gapminder data files. Any errors can be handled by instructors and helpers on the spot, making it much more likely that learners will have their scripts / notebooks open in the correct directories and that their data files are already accessible for future use. By moving out the Markdown material, this change will not lengthen the course (and indeed might shorten it by frontloading all the environment setup).

srtee commented 3 years ago

Alternatively, the material on getcwd and listdir could be placed at the end of Episode 6 (Libraries), which will therefore showcase a very practical and essential example of Python library importing.

Since this would locate the exercise just before Episode 7, where data files are imported for the first time, we would also be introducing all file-system-related material together in a contiguous block and thus make it more memorable and accessible for learners.

eldobbins commented 3 years ago

I really like this idea.

izaakm commented 3 years ago

Hello, I've started adding the os library to Episode 6, introducing the functions getcwd and listdir. It seems like it might be important to also include chdir in case students didn't start Jupyter in their home directory, what do you think?

Just to confirm, the markdown should still be removed from Episode 1? With the goal being to keep the total Lesson length approximately the same.

gabrielesh commented 1 month ago

I'm glad this is still open, as we have been having this same issue. I agree that Markdown is a distraction at this phase, and that understanding working directories is much more important. I have no opinion as to which library to use to find one's working directory. I'd be happy to help work on this if there is momentum.

alee commented 1 month ago

Thanks @gabrielesh, we would welcome any contributions here! I think the rationale for Markdown was to introduce learners to the basic documentation formatting to help them structure any future notebooks they write.

I think the key parts are identifying and reporting the current working directory and using the pathlib module to create relative paths to things on the filesystem for reading or writing

https://github.com/swcarpentry/python-novice-gapminder/pull/559 was a good start towards this though I would still recommend splitting out the removal of Markdown and the addition of working directories and some guidance on getcwd() and pathlib into two separate PRs.