You don't have to put all the code nested under the `with open` — just the bits that access `departments_file`:

```python
with open(file_name) as departments_file:
    departments = json.load(departments_file)

# Create a text file for every department
for d in departments:
    # ...
```

Python's scoping is different from C/C++/Java. `departments` will stay in scope for the entire function.