Skip to content

Commit 7eda05b

Browse files
committed
minor corrections to 3 files exercises
1 parent a50403d commit 7eda05b

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

07-files/files1.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11

2-
# To read and write a file, you have to open a file handler, with the built-in
2+
# To read and write a file, you have to open a file handler using the built-in
33
# `open()` function. Its only required argument is the path to the file.
44

55
# We've used "f"-strings before to incorporate variable values, but now we
66
# need to use an "r"-string: https://www.journaldev.com/23598/python-raw-string
77
# They take backslashes literally — very important in Windows file/dir paths.
88

9+
# This may need to be altered for use on Windows
910
filepath = r'07-files/shopping_list.csv'
1011

1112
file = open(filepath)
1213

14+
# File objects (such as those returned by `open()`) are effectively a list:
1315
for line in file:
14-
print(line, end="")
16+
print(line, end='')
1517

1618
file.close()

07-files/files2.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# script's Current Working Directory (CWD) is the root of the project.
44

55
# We can access the CWD using the `getcwd()` function in the `os` module.
6+
67
import os
78

89
print(os.getcwd())

07-files/files4.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
# You can also use the `readlines()` method to iterate over the lines of a file
23

34
filepath = r'07-files/shopping_list.csv'

0 commit comments

Comments
 (0)