Hello
Welcome
What is the fuck...
f = open("a.txt") lines = f.read() print lines print(type(lines)) f.close()
-
Hello
-
Welcome
-
What is the fuck...
-
<type 'str'> #字符串类型
f = open("a.txt") line = f.readline() print(type(line)) while line: print line, line = f.readline() f.close()
-
<type 'str'>
-
Hello
-
Welcome
-
What is the fuck...
f = open("a.txt") lines = f.readlines() print(type(lines)) for line in lines: print line, f.close()
-
<type 'list'>
-
Hello
-
Welcome
-
What is the fuck...
# 输出第2行 text = linecache.getline(‘a.txt',2) print text,