## Open a file
```python
try:
fhand = open('sample.md')
except:
print('File cannot be opened:', fname)
exit()
```
## Print to a file
The easiest way is just to send the output to a file in the terminal:
`python3 parse.py > output.md`
## Iterating over lines in a file
```python
for line in fhand:
print(line)
```
## Split words in a line
```python
fhand = open('mbox-short.txt')
for line in fhand:
words = line.split()
# print 'Debug:', words
if len(words) == 0: continue
if words[0] != 'From': continue
print(words[2])
```
This puts each word into a list called `words`.
## Write back to a file
```python
with open(fullFilePath + '.png','w') as output_file:
output_file.write(stringToWrite)
```