here is an excellent opportunity to use the "with" statement. So you'll do:

```
with open(path, 'w') as f:
  # do stuff

# no need to close f
```