I would prefer to see:

```python
    s3file = secure_file_storage.open("/%s/%s/reports/exams/%s" % (course_prefix, course_suffix, fname),'w')
    outfile.seek(0)
    try:
        s3file.write(outfile.read())
    finally:
        s3file.close() 
    outfile.close()
```

Probably make sure "outfile" gets closed the same way, just to lazy to type that in here.  Indeed that's the more important one in case of pending files writes not flushed.