Check your understanding of the previous reading: the commands for moving around a file system, absolute and relative paths, and why forward slashes suit Python.

Question 1

Write the command for moving up a directory.

Show worked solution

A pair of periods means the folder one level up, so the command is cd .. (cd ../ works too).

Question 2

Write the command for moving to a folder named "homework" that is in the current directory.

Show worked solution

The folder is in the current directory, so its relative path is simply its name: cd homework.

Question 3

Write the command for printing the current directory.

Show worked solution

PWD stands for Print Working Directory: pwd.

Question 4

Write the command for listing files in the current directory.

Show worked solution

ls stands for "list": it lists the files in the current working directory.

Question 5

Given the following map of a filesystem…

/root/
    python/
        readme.rst
        python.exe
        qt.conf
    classes/
        cs1064/
            adventure_game.py
            assignment2.txt
            ethics_submission.pdf
        dog1223/
            readings.pdf
            project1.docx
            DCIM-1221.jpg
    data/
        survey_results.csv
        state_names.json
        f15_student_logs.txt

Answer the following:

QuestionAnswer
What is the full path to the folder "data/"?
What is the full path to the file "DCIM-1221.jpg"?
If you are currently in directory data/, which of the following is NOT a path to the readings.pdf file?
If you are currently in directory cs1064/, which of the following is NOT a path to the survey_results.csv file?

Question 6

Why should you tend to use forward slashes in Python?

Select every answer that applies, then check.

  • Correct. In a Python string, a backslash starts an escape sequence, so a path with single backslashes can turn into something else. That's why the reading says you would otherwise need to escape the backslashes with extra backslashes.
  • Not a reason. Backslashes are the usual separator on Windows; the trouble is how Python strings treat them.
  • Not a reason. How they look doesn't matter; what matters is that forward slashes need no escaping and work across platforms.
  • Correct. The reading recommends forward slashes because they tend to work regardless of the platform.

Question 7

True or false: The pwd command works in every Python environment.

Select one answer, then check.

  • Not quite. pwd is a command for a command line; it's not actually a Python command, so a Python environment doesn't run it as Python code.
  • Correct. pwd belongs to the command line, not to Python: it's not actually a Python command.