This Is Not The Course Website You Are Looking For

This course website is from a previous semester. If you are currently in the class, please make sure you are viewing the latest course website instead of this old one.

Everyone:

Next week, we will transition from shell scripting and filters to creating more sophisticated scripts using the Python programming language. Using a more advanced scripting language such as Python will allow us to use sequence data structures such as lists and mapping data structures such as dictionaries, and thus perform more sophisticated data manipulation efficiently and effectively.

TL;DR

The focus of this reading is to introduce scripting in Python.

Readings

The readings for this week are:

  1. Scipy Lecture Notes: 1.2. The Python language

  2. A Byte of Python - Data Structures

Optional Resources

Here are some additional resources:

  1. A Byte of Python

  2. Automate The Boring Stuff

Python 3

In this course, we will be using Python 3.x rather than Python 2.x. Although Python 2 is still widely available, it is deprecated and now largely unsupported. Therefore, most new projects and applications are moving to Python 3, so we will follow suit1.

Because Python 3 is not the default on most systems, you may need to install it yourself. On Windows or macOS, I recommend the Anaconda distribution, which includes Python and a bunch of useful libraries and tools.

On the student machines, you can use the instructor's copy of Python by performing the following modifications to your PATH environmental variable:

export PATH=~pbui/pub/pkgsrc/bin:$PATH

This will give you access to a more current version of Python along with some of the libraries we will be using such as Requests.

Quiz

This week, your reading quiz is split into two sections: the first part is your normal dredd quiz, while the second part involves one Python script: exists.py.

To test this script, you will need to download the Makefile and test scripts:

$ git checkout master                 # Make sure we are in master branch
$ git pull --rebase                   # Make sure we are up-to-date with GitHub

$ git checkout -b reading05           # Create reading05 branch and check it out

$ cd reading05                        # Go into reading05 folder

# Download Reading 05 Makefile
$ curl -LO https://raw.githubusercontent.com/nd-cse-20289-sp21/cse-20289-sp21-assignments/master/reading05/Makefile

# Execute tests (and download them)
$ make

Questions

Record the answers to the following Reading 05 Quiz questions in your reading05 branch:

exists.py

Use the echo.py script as the basis for a Python script called exists.py, which accomplishes the same task as the modified version of exists.sh in Reading 02:

# Run script and check error code
$./exists.py * && echo Success
exists.py exists!
README.md exists!
Success

$ ./exists.py * ASDF || echo Success
# Run script and check error code
exists.py exists!
README.md exists!
ASDF does not exist!
Success

Testing

To test your exists.py, you can use the test_exists.sh script downloaded by the Makefile:

$ ./test_exists.sh                    # Test your exists.py
Testing exists.py ...
 exists.py                                ... Success
 exists.py *                              ... Success
 exists.py * ASDF                         ... Success
 exists.py /etc/*                         ... Success
   Score 1.00

Hints

Submission

To submit your work, follow the same process outlined in Reading 01:

#--------------------------------------------------
# BE SURE TO DO THE PREPARATION STEPS ABOVE
#--------------------------------------------------

$ cd reading05                        # Go into reading05 folder
$ $EDITOR answers.json                # Edit your answers.json file

$ ../.scripts/check.py                # Check reading05 quiz
Checking reading05 quiz ...
      Q1 0.30
      Q2 0.40
      Q3 0.30
      Q4 0.20
      Q5 0.80
      Q6 1.00
   Score 3.00 / 3.00
  Status Success

$ git add answers.json                # Add answers.json to staging area
$ git commit -m "Reading 05: Quiz"    # Commit work

$ $EDITOR exists.py                   # Edit your exists.py file

$ ./test_exists.sh                    # Test your exists.py
Testing exists.py ...
 exists.py                                ... Success
 exists.py *                              ... Success
 exists.py * ASDF                         ... Success
 exists.py /etc/*                         ... Success
   Score 1.00

$ git add Makefile                    # Add Makefile to staging area
$ git add exists.py                   # Add exists.py to staging area
$ git commit -m "Reading 05: Scripts" # Commit work

$ git push -u origin reading05        # Push branch to GitHub

Pull Request

Remember to create a Pull Request and assign the appropriate TA from the Reading 05 TA List.

DO NOT MERGE your own Pull Request. The TAs use open Pull Requests to keep track of which assignments to grade. Closing them yourself will cause a delay in grading and confuse the TAs.


  1. As a luddite, this breaks my heart, but there is no point in yelling at clouds. Evolve or die.