Skip to content

Commit 22356bc

Browse files
author
chenym
committed
add
1 parent 8a27273 commit 22356bc

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

1 File handle/File handle text/file handle 12 length of line in text file.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
def longlines():
22
F = open("story.txt", "r")
3-
line = F.readlines()
3+
line = F.readlines() #按行读取
44

55
for i in line:
66
if len(i) < 50:

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

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,15 @@
22
import sys
33

44
sys.stdout.write("Enter the name of the file")
5-
file = sys.stdin.readline()
65

6+
#sys.stdout是python中的标准输出流,默认是映射到控制台的,即将信息打印到控制台。
7+
file = sys.stdin.readline()
8+
print(file)
79
F = open(file.strip(), "r")
8-
10+
print(F.readlines())
911
while True:
1012
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
13+
for i in ch:
1614
print(i, end="")
17-
else:
18-
sys.stderr.write("End of file reached")
19-
break
15+
2016
F.close()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
once upon a time there was a king.
22
he was powerful and happy.
33
he had a garden.
4+
5+
46
all the flowers in his garden was beautiful.
57
he lived happily forever.

0 commit comments

Comments
 (0)