标签:cep not file 小练习 ret def exce imp +=
import os.path def read_specific_line(file_path,line_number,encoding="utf-8"): if not os.path.exists(file_path): return None if not isinstance(line_number,int): return None content = None try: fp = open(file_path,"r",encoding=encoding) n=1 for line in fp: if n==line_number: content = line fp.close() return content n+=1 fp.close() except: print("编码设定错误,请更换编码参数重试!") return content print(read_specific_line("e:\\a.txt",3,"utf-8"))
标签:cep not file 小练习 ret def exce imp +=
原文地址:https://www.cnblogs.com/wenm1128/p/11627988.html