当前位置:天才代写 > tutorial > Python教程 > python 异常处理

python 异常处理

2018-05-17 08:00 星期四 所属: Python教程 浏览:331

python">def main():
    try:
        for line in readfile('lines.txt'): print(line.strip()) 
    except IOError as e:
        print('could not open the file:',e)
    except ValueError as e:
        print('bad filename:',e)    

def readfile(filename):
    if filename.endswith(".txt"):        
        fh = open(filename)
        return fh.readlines()
    else: raise ValueError("file must be ends with .txt")

if __name__ == "__main__": main()

标签:python

 

    关键字:

天才代写-代写联系方式