
Snipper
A lightweight framework for removing code from student solutions.
Installation
pip install codesnipper
What it does
This project address the following three challenges for administering a python-based course
- Maintain a (working) version for debugging as well as a version handed out to students (with code missing)
- Use LaTeX references in source code to link to course material (i.e.
\ref{mylabel}
-> "(see equation 2.1 in exercise 5)") - Including code snippets and console output in lectures notes/exercises/beamer slides
- Automatically create student solutions
This framework address these problems and allow you to maintain a single, working project repository. Below is an example of the snippets produced and included using simple \inputminted{python}{...}
commands (see the examples/
directory):
The project is currently used in 02465 at DTU. An example of student code can be found at:
A set of lectures notes where all code examples/output are automatically generated from the working repository can be found a
- https://lab.compute.dtu.dk/tuhe/books (see Sequential decision making)
Usage
All examples can be found in the /examples
directory. The idea is all our (complete) files are found in the instructor directory and snipper keeps everything up-to-date:
examples/cs101_instructor # This directory contains the (hidden) instructor files. You edit these
examples/cs101_students # This directory contains the (processed) student files. Don't edit these
examples/cs101_output # This contains automatically generated contents (snippets, etc.).
The basic functionality is you insert special comment tags in your source, such as #!b
or #!s
and the script then process
the sources based on the tags. The following will show most common usages:
The #!f-tag
Let's start with the simplest example, blocking out a function (see examples/cs101_instructor/f_tag.py
; actually it will work for any scope)
You insert a comment like: #!f <exception message>
like so:
def myfun(a,b): #!f return the sum of a and b
""" The doc-string is not removed. """
sm = a+b
return sm