Skip to content

Commit e932239

Browse files
committed
added better file handling
added better file handling to file handle 12 length of line in text file.py Fixed a few grammatical errors is story.txt
1 parent d145c84 commit e932239

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed
Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
def longlines():
2-
F = open("story.txt", "r")
3-
line = F.readlines()
2+
with open('story.txt', encoding='utf-8') as F:
3+
line = F.readlines()
44

5-
for i in line:
6-
if len(i) < 50:
7-
print(i, end=" ")
8-
9-
F.close()
5+
for i in line:
6+
if len(i) < 50:
7+
print(i, end=" ")
108

119

1210
longlines()
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
once upon a time there was a king.
22
he was powerful and happy.
33
he had a garden.
4-
all the flowers in his garden was beautiful.
5-
he lived happily forever.
4+
all the flowers in his garden were beautiful.
5+
he lived happily ever after.

0 commit comments

Comments
 (0)