Semi Open Book Exams

A few years ago, I switched one of my first year courses to use what I call a semi-open-book approach.

Open-book exams of course allow students to bring whatever materials they wish into them, but they have the disadvantage that students will often bring in materials that they have not studied in detail, or even at all. In such cases, sifting through materials to help them answer a question could be counter productive.

On the other hand, the real world is now an increasingly “open-book” environment, which huge amounts of information available to those in the workplace which is now almost always Internet connected.

So I decided to look at another approach. Students are allowed to bring in a single, personalised, A4 sheet, on which they can write whatever they wish on both sides. There are a few rules:

  • the sheet must be written on “by hand”, that is to say, it cannot be printed to from a computer, or typed;
  • the sheet must be “original”, that is to say, it cannot be a photocopy of another sheet (though students may of course copy their original for reference);
  • the sheet must be the student’s own work, and they must formally declare as much (with a tick box);
  • the sheet must be handed in with the exam paper, although it is not marked.

The purpose of these restrictions are to ensure that each student takes a lead in producing an individual sheet, and to inhibit cottage industries of copied sheets.

In terms of what can go on the sheet? Well anything really. It can be sections from notes, important formulae, sample questions or solutions. The main purpose here is to prompt students to work out what they would individually distill down to an A4 page. So they go through all the module notes, tutorial problems and more, and work out the most valuable material that deserves to go on one A4 page. I believe that this process itself is the greatest value of the sheet, its production rather than its existence in the exam. I’m working on some research to test this.

So I email them each an A4 PDF, which they can print out at home, and on whatever colour paper they may desire. The sheet is individual and has their student number on it with a barcode, for automated processing and analysis afterwards for a project I’m working on, but this is anonymised. The student’s name in particular does not appear, since in Ulster University, it does not appear on the exam booklet.

The top of my sheet looks like this:

The top of a sample guide sheet.

So, if you would like to do the same, I am enclosing the Python script, and LaTeX that I use to achieve this. You could of course use any other technology, or not individualise the sheet at all.

For convenience the most recent code will also be placed on a GitHub repository here, feel free to clone away.

My script has just been rewritten for Python 3.x, and I’ve added a lot of command line parameters to decouple it from me and Ulster University only use. It opens a CSV file from my University which contains student id numbers, student names, and emails in specific columns. These are the default for the script but can be changed. For each student it uses LaTeX to generate the page. It actually creates inserts for each student of the name and student number, you can then edit open-book.tex to allow the page to be as you wish it. You don’t need to know much LaTeX to achieve this, but ping me if you need help. I am also using a LaTeX package to create the barcodes automatically.

I’ve spent a bit of time adding command line parameters to this script, but you can try using

python3 --help

for information. The script has been rewritten for Python 3. If you run it without parameters it will enter interactive mode and prompt you.

I’d strongly recommend running with the –test-only option at first to make sure all looks good, and opening open-book.pdf will show you the last generated page so you can see it’s what you want.

Anyway, feel free to do your own thing, or mutilate the code. Enjoy!

#!/usr/bin/env python

# Copyright Colin Turner 2014-2017
# Free and Open Source Software under GPL v3
import argparse

import csv
import re
import subprocess
import smtplib
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

def process_student(args, row):
    """Takes a line from the CSV file, you will likely need to edit aspects of this."""
    'kicks of the processing of a single student'
    student_number = row[args.student_id_column]
    student_name = row[args.student_name_column]
    student_email = row[args.student_email_column]
    print('  Processing:', student_name , ':', student_email)
    create_latex_inserts(student_number, student_name)
    send_email(args, student_name, student_email)

def create_latex_inserts(student_number, student_name):
    """Write LaTeX inserts for the barcode and student name

    For each student this will create two tiny LaTeX files:

     * open-book-insert-barcode.tex which contains the LaTeX code for a barcode representing the student number
     * open-book-insert-name.tex which will contain simply the student's name

    These files can be included/inputted from open-book.tex as desired to personalise that document

    student_number is the ID in the students record system for the student
    student_name is the name of the student"""

    # Open a tiny LaTeX file to put this in
    file = open('open-book-insert-barcode.tex', 'w')

    # All the file contains is LaTeX to code to create the bar code
    string = '\psbarcode{' + student_number + '}{includetext height=0.25}{code39}'

    # The same exercise for the second file to contain the student name
    file = open('open-book-insert-name.tex', 'w')
    string = student_name

def create_pdf():
    """Calls LaTeX and dvipdf to create the personalised PDF with inserts from create_latex_inserts()"""

    # Suppress stdout, but we leave stderr enabled."latex open-book", stdout=subprocess.DEVNULL, shell=True)"dvipdf open-book", stdout=subprocess.DEVNULL, shell=True)

def send_email(args, student_name, student_email):
    """Emails a single student with the generated PDF."""
    #TODO: Might be useful to improve the to address
    #TODO: Allow subject to be tailored.

    subject = args.email_subject
    from_address = args.email_sender
    # to_address = student_name + ' <' + student_email + '>'
    to_address = student_email

    msg = MIMEMultipart()
    msg['Subject'] = subject
    msg['From'] = from_address
    msg['To'] = to_address

    text = 'Dear Student\nPlease find enclosed your guide sheet template for the exam. Read the following email carefully.\n'
    part1 = MIMEText(text, 'plain')

    # Open the files in binary mode.  Let the MIMEImage class automatically
    # guess the specific image type.
    fp = open('open-book.pdf', 'rb')
    img = MIMEApplication(, 'pdf')


    # Send the email via our own SMTP server, if we are not testing.
    if not args.test_only:
        s = smtplib.SMTP(args.smtp_server)
        s.sendmail(from_address, to_address, msg.as_string())

def override_arguments(args):
    """If necessary, prompt for arguments and override them

    Takes, as input, args from an ArgumentParser and returns the same after processing or overrides.

    # If the user enabled batch mode, we disable interactive mode
    if args.batch_mode:
        args.interactive_mode = False

    if args.interactive_mode:
        override = input("CSV filename? default=[{}] :".format(args.input_file))
        if len(override):
            args.input_file = override

        override = input("Student ID Column? default=[{}] :".format(args.student_id_column))
        if len(override):
            args.student_id_column = int(override)

        override = input("Student Name Column? default=[{}] :".format(args.student_name_column))
        if len(override):
            args.student_name_column = int(override)

        override = input("Student Email Column? default=[{}] :".format(args.student_email_column))
        if len(override):
            args.student_email_column = int(override)

        override = input("Student ID Regular Expression? default=[{}] :".format(args.student_id_regexp))
        if len(override):
            args.student_id_regexp = override

        override = input("SMTP Server? default=[{}] :".format(args.smtp_server))
        if len(override):
            args.smtp_server = override

        override = input("Email subject? default=[{}] :".format(args.email_subject))
        if len(override):
            args.email_subject = override

        override = input("Email sender address? default=[{}] :".format(args.email_sender))
        if len(override):
            args.email_sender = override


def parse_arguments():
    """Get all the command line arguments for the file and return the args from an ArgumentParser"""

    parser = argparse.ArgumentParser(
        description="A script to email students study pages for a semi-open book exam",
        epilog="Note that column count arguments start from zero."


    parser.add_argument('-b', '--batch-mode',
                        help='run automatically with values given')

                        help='prompt the user for details (default)')

    parser.add_argument('-i', '--input-file',
                        help='the name of the input CSV file with one row per student')

    parser.add_argument('-sidc', '--student-id-column',
                        help='the column containing the student id (default 1)')

    parser.add_argument('-snc', '--student-name-column',
                        help='the column containing the student name (default 2)')

    parser.add_argument('-sec', '--student-email-column',
                        help='the column containing the student email (default 9)')

    parser.add_argument('-sidregexp', '--student-id-regexp',
                        help='a regular expression for valid student IDs (default B[0-9]+)')

                        help='the address of an smtp server')

                        default='IMPORTANT: Your semi-open-book Guide Sheet',
                        help='the subject of emails that are sent')

                        help='the sender address from which to send emails')

    parser.add_argument('-t', '--test-only',
                        help='do not send any emails')

    args = parser.parse_args()

    # Allow for any overrides from program logic or interaction with the user
    args = override_arguments(args)

def main():
    """the main function that kicks everything else off"""

    args = parse_arguments()

    print("Starting open-book...")
    csvReader = csv.reader(open(args.input_file, 'r'), dialect='excel')

    student_count = 0
    # Go through each row
    for row in csvReader:
        student_number = row[args.student_id_column]
        # Check if the second cell looks like a student number
        if re.match(args.student_id_regexp, row[args.student_id_column]):
            student_count = student_count + 1
            process_student(args, row)
            print('  Skipping: non matching row')

    print('Stopping open-book...')

if __name__ == '__main__':

I use a LaTeX template for the base information, this can be easily edited for taste.


% Does it all have to be Arial now? <sigh>

\author{Professor Colin Turner}
\textbf{EEE122 Examination Guide Sheet}

This sheet, and its contents that you have added, can be brought into
the examination for EEE122. The contents \textbf{must} be compiled
by yourself, be handwritten, and be original (i.e. \textbf{NOT} 
photocopied or similar). You may use the
reverse side. You may retain a copy you have made before the examination
but the original must be handed in with your examination scripts at the
end of your examination.

% D'Oh! Not supposed to put a name on anything going in the exam.
%}{includetext height=0.25}{code39}

Please read the following declaration and tick the box to indicate you agree:

I declare this sheet to have been compiled by myself and not by another, and that the student number above is mine.

%\rule[-1 cm]{10 cm}{1 pt}
\framebox[0.3 cm]{ }



Leave a Reply

Your email address will not be published. Required fields are marked *