> For the complete documentation index, see [llms.txt](https://george-jen.gitbook.io/data-science-and-apache-spark/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://george-jen.gitbook.io/data-science-and-apache-spark/output-to-a-file.md).

# Output to a file

### Output to a file:

```
with open('/tmp/test.out','w') as fp:
    for i in range(5):
        fp.write(str(i))
#It writes into file /tmp/test.out below:
%cat /tmp/test.out
```

01234
