Learning immediately: https://edu.csdn.net/course/play/24797/282197?utm_source=blogtoedu
# ReadLine while loop to read all rows # the try: # F = Open ( 'test44.py', 'R & lt', True, 'UTF-. 8') # the while True: # = f.readline Data () # Data Not IF : # BREAK # Print (Data, End = '') # AS OSError the except E: # Print (E) # Print (e.errno) # Print (e.args) # Print (e.strerror) # the finally: # IF 'F' in Globals (): # f.close () # readLines cycles to read all rows # the try: # F = Open ( 'test44.py', 'R & lt', True, 'UTF-. 8') # # returns is a list # = f.readlines Data () # Data for I in: # 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('出现问题了')