Skip to content

Commit e354fd3

Browse files
authored
Update 02-file_parsing.md
1 parent 85b7c64 commit e354fd3

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

_episodes/02-file_parsing.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,16 @@ outfile.close()
108108
~~~
109109
{: .language-python}
110110

111-
## Alternative way to open a file:
112-
Alternatively, you can open a file using `context-manager`. In this case, python will automatically handle closing of the file:
113-
```python
114-
with open(ethanol_file,"r") as outfile:
115-
data = outfile.readlines()
116-
```
111+
> ## An alternative way to open a file.
112+
> Alternatively, you can open a file using `context-manager`. In this case, the context manager will automatically handle closing of the file. To use a context manager to open and close the file, you use the word `with`, and put everything you want to be done while the file is open in an indented block.
113+
> ~~~
114+
> with open(ethanol_file,"r") as outfile:
115+
> data = outfile.readlines()
116+
> ~~~
117+
> {: .language-python}
118+
>
119+
> This is often the preferred way to deal with files because you do not have to remember to close the file.
120+
{: .callout}
117121
118122
119123
> ## Check Your Understanding

0 commit comments

Comments
 (0)