立即学习:https://edu.csdn.net/course/play/24797/282197?utm_source=blogtoedu
# readLine while 循环读取所有行 # try: # f = open('test44.py', 'r', True, 'utf-8') # while True: # data = f.readline() # if not data: # break # print(data, end='') # except OSError as e: # print(e) # print(e.errno) # print(e.args) # print(e.strerror) # finally: # if 'f' in globals(): # f.close() # readLines 循环读取所有行 # try: # f = open('test44.py', 'r', True, 'utf-8') # #返回的是一个列表 # data = f.readlines() # for i in data: # print(i,end='') # print(data, end='') # except OSError as e: # print(e) # print(e.errno) # print(e.args) # print(e.strerror) # finally: # if 'f' in globals(): # f.close() # for 方法 读取所有数据 # try: # f = open('test44.py', 'r', True, 'utf-8') # for i in f: # print(i,end='') # except OSError as e: # print(e) # print(e.errno) # print(e.args) # print(e.strerror) # finally: # if 'f' in globals(): # f.close() # lincache.getline # import linecache # try: # #data = linecache.getline('test44.py',10) # data = linecache.getlines('test44.py') # print(data) # for i in data: # print(i,end='') # except: # print('出现问题了') # lincache.getline import linecache try: # data = linecache.getline('test44.py',10) data = linecache.getlines(linecache.__file__) print(data) for i in data: print(i, end='') except: print('出现问题了')