Skip to content

Commit bd79783

Browse files
committed
added better file handling
added better file handling in input,output and error streams.py fixed spelling and grammatical errors in happy.txt
1 parent e932239 commit bd79783

File tree

2 files changed

+13
-17
lines changed

2 files changed

+13
-17
lines changed

1 File handle/File handle text/happy.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ hello how are you
22
what is your name
33
do not worry everything is alright
44
everything will be alright
5-
please dont loose hope
6-
Wonders are in the way
5+
please don't lose hope
6+
Wonders are on the way
77
Take a walk in the park
8-
In the end of the day you are more important than anything else.
8+
At the end of the day you are more important than anything else.
99
Many moments of happiness are waiting
1010
You are amazing!
11-
Its true believe.
11+
If you truly believe.

1 File handle/File handle text/input,output and error streams.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,13 @@
44
sys.stdout.write("Enter the name of the file")
55
file = sys.stdin.readline()
66

7-
F = open(file.strip(), "r")
7+
with open(file.strip(), ) as F:
8+
9+
while True:
10+
ch = F.readlines()
11+
for (i) in ch: # ch is the whole file,for i in ch gives lines, for j in i gives letters,for j in i.split gives words
12+
print(i, end="")
13+
else:
14+
sys.stderr.write("End of file reached")
15+
break
816

9-
while True:
10-
ch = F.readlines()
11-
for (
12-
i
13-
) in (
14-
ch()
15-
): # ch is the whole file,for i in ch gives lines, for j in i gives letters,for j in i.split gives words
16-
print(i, end="")
17-
else:
18-
sys.stderr.write("End of file reached")
19-
break
20-
F.close()

0 commit comments

Comments
 (0)