You don't need to do f.close() when in a context manager.  The file closes automatically when you leave that block (which is the advantage of using them.)  ie you can get away with simply doing

```python
with open(filename, 'a') as f:
    f.write(s)
```